home *** CD-ROM | disk | FTP | other *** search
/ Internet Tools (InfoMagic) / Internet Tools.iso / dos_win / winsock / wsock20 / ws2spi.txt < prev    next >
Text File  |  1994-12-16  |  397KB  |  9,224 lines

  1.                              ii
  2.  
  3.                               
  4.                               
  5.                               
  6.                       Windows Sockets 2
  7.                        Service Provider
  8.                           Interface
  9.                               
  10.                               
  11.     A Service Provider Interface for Transparent Network
  12.              Programming under Microsoft Windows
  13.                               
  14.                               
  15.                        Revision 20.043
  16.                       December 79, 1994
  17.                               
  18.                           Winsock 2
  19.                               
  20.                               
  21.                               
  22.               Subject to Change Without Notice
  23.                               
  24.                               
  25.                               
  26.                               
  27.                               
  28.                               
  29.  
  30.                               
  31.                          Disclaimer
  32.  
  33. Microsoft, Intel, and JSB disclaim all warranties and
  34. liability for the use of this document and the information
  35. contained herein, and assume no responsibility for any
  36. errors which may appear in this document. Microsoft, Intel,
  37. and JSB make no warranty or license regarding the
  38. relationship of this document and the information contained
  39. herein to the intellectual property rights of any party.
  40. Microsoft, Intel, and JSB make no commitment to update the
  41. information contained herein.
  42.  
  43.  
  44.            Winsock 2.0 Service Provider Interface
  45.                               
  46. TABLE OF CONTENTS
  47.  
  48. TABLE OF CONTENTS                                        iii
  49. 1. INTRODUCTION                                          1
  50.      1.1 Winsock Specification is a WOSA Component       1
  51.           1.1.1 Winsock 2 DLLs                           1
  52.      1.2 Microsoft Windows and Windows-specific
  53.      extensions                                          2
  54.      1.3 Naming Conventions                              2
  55. 2. OVERVIEW                                              3
  56.      2.1 Configuration of Winsock Service Providers      3
  57.           2.1.1 Registry Layout for Windows NT and
  58.           Windows 95                                     3
  59.                2.1.1.1 Providers                         3
  60.                2.1.1.2 Provider-specific Keys            3
  61.           2.1.2 WINSOCK2.INI Layout for Windows 3.1      5
  62.                2.1.2.1 Providers                         6
  63.                2.1.2.2 Provider-specific Sections
  64.                ([Provider-<Provider Key>])               6
  65.      2.2. Service Providers Interface Model              8
  66.      2.3 Initialization of Winsock Service Providers     8
  67.      2.4 Functionality Implemented Within the Winsock
  68.      DLL                                                 9
  69.      2.5 Functionality Implemented by Service Providers  9
  70.      2.6 Differences and Similarities Between Winsock
  71.      API and SPI                                         9
  72.      2.7 Differences Between 32-bit and 16-bit Winsock
  73.      SPI                                                 10
  74.      2.8 Sockets                                         10
  75.           2.8.1 Out-of-band data                         10
  76.           2.8.2 Socket Options                           11
  77.      2.9 Quality of Service (QOS)                        13
  78.           2.9.1 Overall Approach                         13
  79.           2.9.2 The Flow Spec Structure                  14
  80. 3. SERVICE PROVIDER INTERFACE REFERENCE                  15
  81.      3.1 Socket Routines                                 15
  82.           3.1.1 WSPBind()                                16
  83.           3.1.2 WSPCloseSocket()                         18
  84.           3.1.3 WSPGetPeerName()                         19
  85.           3.1.4 WSPGetSockName()                         20
  86.           3.1.5 WSPGetSockOpt()                          22
  87.           3.1.6 WSPIoctlSocket()                         27
  88.           3.1.7 WSPListen()                              29
  89.           3.1.8 WSPSelect()                              31
  90.           3.1.9 WSPSetSockOpt()                          34
  91.           3.1.10 WSPShutdown()                           38
  92.           3.1.11 WSPAccept()                             40
  93.           3.1.12 WSPAsyncSelect32()                      43
  94.           3.1.13 WSPCallbackSelect16()                   49
  95.           3.1.14 WSPCancelBlockingCall32()               55
  96.           3.1.15 WSPCleanup()                            57
  97.           3.1.16 WSPConnect()                            59
  98.           3.1.17 WSPEnumNetworkEvents()                  64
  99.           3.1.18 WSPEventSelect()                        66
  100.           3.1.19 WSPIsBlocking32()                       71
  101.           3.1.20 WSPRecv()                               72
  102.           3.1.21 WSPRecvFrom()                           75
  103.           3.1.22 WSPSend()                               78
  104.           3.1.23 WSPSendTo()                             81
  105.           3.1.24 WSPSetBlockingHook32()                  85
  106.           3.1.25 WSPSocket()                             87
  107.           3.1.26 WSPStartup()                            89
  108.           3.1.27 WSPUnhookBlockingHook32()               93
  109. 4. Upcalls                                               94
  110.      4.1 WPUCreateSocketHandle()                         95
  111.      4.2 WPUCloseSocketHandle()                          96
  112.      4.3 WPUQuerySocketHandleContext()                   97
  113.      4.4 WPUSetSocketHandleContext()                     98
  114.      4.5 WPUQueueUserAPC32()                             99
  115.      4.6 WPUGetCurrentThreadId32()                       100
  116. 5. Installation APIs                                     101
  117.      5.1 WPUInstallProvider()                            101
  118.      5.2 WPUDeinstallProvider()                          102
  119. Appendix A. Error Codes and Header Files                 103
  120.      A.1 Error Codes                                     103
  121.      A.2 Winsock SPI Header File - ws2spi.h              105
  122. Appendix B. Notes for Winsock Service Providers          120
  123.      B.1 Introduction                                    120
  124.      B.2 Winsock SPI Run Time Components                 120
  125.      B.3 Error Codes                                     120
  126. Appendix C. Outstanding Issues                           121
  127. .
  128. {General comments: This is really coming along and you guys
  129. (I assume Keith in particular) have really done some nice
  130. work. The most important thing we need to fix (which I think
  131. must be done before the 12th) is to get the service provider
  132. model established correctly. See my comments in section
  133. 2.2.1.2 for details. Other than that, my corrections which
  134. are sprinkled liberally throughout the document are mostly
  135. minor issues. Note that I did suggest appending `32' onto
  136. the names of WSPSelect() as well as a few others. Also, I
  137. would really like to thin down the opens section some so
  138. that we don't distract the larger group onto what are
  139. essentially DLL implementationimplemenation issues. See my
  140. comments at the end of the doc for details.
  141.  
  142. Sooner or later we are going to have to do a very thorough
  143. and careful editing job on this document so that it always
  144. speaks from the perspective of a service provider interface
  145. spec as opposed to an application programming interface
  146. perspective. I realize that the PII SPI had all of these
  147. same problems, but we still have to fix this. In many places
  148. it is quite obvious that we just did a cut and paste from
  149. the API spec without really fixing all the text
  150. appropriately. This does not need to be done by the 12th,
  151. but we need to nail down a reasonable date by which we will
  152. do this. }
  153. 1. INTRODUCTION
  154.  
  155. This document defines the Service Provider Interface (SPI)
  156. of Windows Socket (Winsock) 2.0. The Winsock SPI specifies
  157. the external interface of a service provider to be
  158. implemented by vendors of network protocol stacks.
  159. Installing a service provider allows Windows applications
  160. written to the Winsock 2 API interface to access the service
  161. provider'scorresponding network protocol stacks. This will
  162. permit one or more applications to have access to multiple
  163. protocol stacks simultaneously.
  164.  
  165. 1.1 Winsock Specification is a WOSA Component
  166.  
  167. The Winsock network transport services are provided as a
  168. WOSA (Windows Open Services Architecture) component. They
  169. consist of both an application programming interface (API)
  170. used by applications and a service provider interface (SPI)
  171. implemented by service providers. This document is designed
  172. to be a stand-alone reference for Winsock service provider
  173. developers. Readers intending to write network applications
  174. should refer to the document "Windows Socket Interface,
  175. revision 2.0" which describes Winsock 2 API.
  176.  
  177. Windows Open Service Architecture (WOSA) provides a single-
  178. level interface for connecting front-end applications with
  179. back-end services. The front-end application and back-end
  180. service need not speak each other's language in order to
  181. communicate as long as they both know how to talk to the
  182. WOSA interface. As a result, WOSA allows application
  183. developers and vendors of back-end services to mix and match
  184. applications and services to build solutions that shield
  185. programmers and users from the underlying complexity of the
  186. system. WOSA defines an abstraction layer to heterogeneous
  187. computing resources through the WOSA set of APIs. Because
  188. this set of APIs is extensible, new services and their
  189. corresponding APIs can be added as needed. Applications
  190. written to the WOSA APIs have access not only to all the
  191. various computing environments supported today, but also to
  192. all additional environments as they become available.
  193. Moreover, applications don't have to be modified in any way
  194. to enjoy this support.
  195.  
  196. Each service recognized by WOSA also has a set of interfaces
  197. that service-provider vendors use to take advantage of the
  198. seamless interoperability that WOSA provides. In order to
  199. provide transparent access for applications, each
  200. implementation of a particular WOSA service simply needs to
  201. support the functions defined by its service-provider
  202. interface.
  203.  
  204. WOSA uses a Windows dynamic-link library (DLL) that allows
  205. software components to be linked at runtime. In this way,
  206. applications are able to connect to services dynamically. An
  207. application needs to know only the definition of the
  208. interface, not its implementation.
  209. 1.1.1 Winsock 2 DLLs
  210.  
  211. Winsock network services follow the WOSA model. This means
  212. that there exists a Winsock Application Programming
  213. Interface (API), which is the application programmer's
  214. access to network services, a Winsock Service Provider
  215. Interface (SPI) which is implemented by network service
  216. provider vendors, and the Winsock DLL. For 16 bit
  217. applications this DLL is referred to as (WINSOCK2.DLL for 16-
  218. bit applications, while 32 bit applications use WSOCK32.DLL
  219. for 32-bit applications). Note that in Windows 3
  220. environments, only Winsock2.DLL will be available, while
  221. Windows 95 and Windows NT support both DLLs. Winsock 2's
  222. WOSA compliant architecture is illustrated below in See
  223. Figure 111Figure 1Figure 1.
  224.  
  225.  
  226.                               
  227.                          Figure 111
  228.  
  229.  
  230. 1.2 Microsoft Windows and Windows-specific extensions
  231.  
  232. This SPI is intended to be usable within all implementations
  233. and versions of Microsoft Windows including Windows NT,
  234. Windows 95, Windows 3.11, and Windows 3.1.
  235.  
  236. Winsock makes provisions for multithreaded Windows
  237. processes. In the non-preemptive Win16 environment, a task
  238. corresponds to a process with a single thread of execution.
  239. In the preemptive Win32 environment, a process contains one
  240. or more threads of execution.
  241. The Microsoft Windows extensions included in PII are
  242. provided to allow application developers to create software
  243. which conforms to the Windows programming model.  It is
  244. expected that this will facilitate the creation of robust
  245. and high-performance applications, and will improve the
  246. cooperative multitasking of applications within non-
  247. preemptive versions of Windows.  With the exception of
  248. PSStartup() and PSCleanup() their use is not mandatory.
  249.  
  250. 1.3 Naming Conventions
  251.  
  252. The Winsock SPI uses the same naming conventions for
  253. functions, messages, and parameters as those used by the
  254. Winsock API except that all the functions are prefixed by
  255. WSP, which stands for Winsock Service Provider.
  256.  
  257. SPI functions applicable only specific to a particular
  258. platform end in an identifying suffix. For example,
  259. WSPCallbackSelect16() is applicable only specific to 16-bit
  260. Windows, and WSPAsyncSelect32() is applicable onlyspecific
  261. to 32-bit Windows.
  262.  
  263. "Upcalls" (utility functions made available by the Winsock
  264. DLL for use by SPI DLLs and installation programs) are
  265. prefixedprevixed by WPU, which stands for Winsock Provider
  266. Upcall.
  267. 2. OVERVIEW
  268.  
  269. 2.1 Configuration of Winsock Service Providers
  270.  
  271. When a service provider is installed, some configuration
  272. information must be added to a configuration database to
  273. give the Winsock DLL required information regarding the
  274. service provider. A service provider vendor must arrange for
  275. this information to be updated as part of the service
  276. provider installation.
  277.  
  278. Under Windows NT and Windows 95, this configuration
  279. information is stored in the system registry. Under Windows
  280. 3.1 and 3.11, this configuration information is stored in
  281. the WINSOCK2.INI file.
  282.  
  283. 2.1.1 Registry Layout for Windows NT and Windows 95
  284.  
  285. All provider configuration information is stored under the
  286. following registry key:
  287.  
  288.      HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Win
  289.      sock2
  290.      
  291. Throughout this document, all references to relative subkeys
  292. and values are assumed to exist under this main Winsock2
  293. registry key. For example, any reference to the "Providers"
  294. subkey is actually a reference to the
  295. "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Winsock
  296. 2\Providers" key.
  297.  
  298. 2.1.1.1 Providers
  299.  
  300. The "Providers" subkey contains one subkey for each
  301. installed service provider. The maximum length of provider
  302. subkey names is 32 characters. These subkeys are created by
  303. any software that installs service providers.
  304.  
  305. The "ProviderOrder" subkey contains zero or more values used
  306. to locate the active service providers. These values also
  307. establish a priority ordering of service providers. The name
  308. of each value represents an active service provider. For
  309. example:
  310.  
  311.      \ProviderOrder
  312.           Microsoft TCP/IP = REG_SZ ""
  313.           novlwp = REG_SZ ""
  314.           TC&S = REG_SZ ""
  315.      
  316. 2.1.1.2 Provider-specific Keys
  317. { This section needs some additional thought. PII's view of
  318. the world was that there was some number of service
  319. providers, each of which supported exactly one address
  320. family and one or more different socket types. (PII
  321. basically ignored the protocol value, since it was almost
  322. always specified as zero .) It was generally assumed that
  323. each socket type corresponded to a different protocol (e.g.
  324. UDP vs.vs TCP), but that all of the different protocols or
  325. socket types were supplied by the single DLL referenced in
  326. the provider section. Thus for PII, a standard TCP/IP stack
  327. would show up as one provider that supported two different
  328. socket types (SOCK_STREAM and SOCK_DGRAM).
  329.  
  330. The WS2 view of the world is that each service provider
  331. encompasses exactly one protocol which is uniquely
  332. identified by its protocol value. I believe there needs to
  333. be a 1:1 mapping between service provider entries and
  334. PROTOCOL_INFO structs returned by WSAEnumProtocols(). As
  335. such we need to make sure that all of the information needed
  336. to create the PROTOCOL_INFO structs appear in the service
  337. provider entries (registry or INI file as appropriate).
  338. Since each service provider entry corresponds to a single
  339. protocol, it naturally supports a single address family as
  340. well. However, in the case of a multi-behaviored protocol
  341. like SPX, there may be more than one possible socket type
  342. value that can be used. It is this socket type value which a
  343. service provider would use to determine which of the
  344. available behaviors an application desires. Thus for
  345. example, a standard TCP/IP stack would show up as two
  346. service providers: one for the UDP protocol and one for the
  347. TCP protocol, even though both such providers refer to the
  348. same service provider DLL.
  349.  
  350. The descriptions in this section assume the PII model of
  351. service providers which is, I believe, at variance with the
  352. proposed Winsock 2 model. It is very important that we are
  353. all on the same page here and that the SPI document clearly
  354. describes how this works.
  355.  
  356. Each Winsock service provider must have a unique subkey
  357. under the "Providers" subkey. It is the responsibility of
  358. the service provider to create its provider-specific subkey
  359. at the time it is installed. It is also the responsibility
  360. of the service provider to delete its provider-specific
  361. subkey at the time it is removed. Only the service provider
  362. writes values in its provider-specific subkey. The Winsock
  363. DLL reads only the following values in the provider-specific
  364. subkey. Other values in the subkey are permitted for
  365. internal use by the service provider. This subkey consists,
  366. at a minimum, of the following:
  367.  
  368.      \Provider\<Provider Name>
  369.      ProviderFilename = REG_SZ "<filename>"
  370.      ProviderDescription = REG_SZ "<Description of the
  371.      provider>"
  372.      ProviderDomain = REG_DWORD <Address family>
  373.      ProviderAddrLength = REG_DWORD <length>
  374.      NumSockets = REG_DWORD <count>  { PII model implied }
  375.      SocketType<index> = REG_DWORD <Socket Type>
  376.      AddressFamily<index> = REG_DWORD <Address Family>
  377.      Protocol<index> = REG_DWORD <Protocol>
  378.      MinimumAddressLength<index> = REG_DWORD <Minimum
  379.      Address Length>
  380.      MaximumAddressLength<index> = REG_DWORD <Maximum
  381.      Address Length>
  382.      ProtocolAttributes<index> = REG_DWORD <Protocol
  383.      Attributes>
  384.      ProtocolSocketDescription<index> = REG_SZ "<Description
  385.      of the protocolsocket>"
  386.      
  387. For example:
  388.  
  389. \Provider\novlwp
  390. ProviderFilename = REG_SZ "novlwp.WPSP"
  391. ProviderDescription = REG_SZ "Novell LAN WorkPlace for
  392. DOS"
  393.  ProviderDomain = REG_DWORD 2
  394. ProviderAddrLength = REG_DWORD 8
  395. NumSockets = REG_DWORD 3
  396. SocketType0 = REG_DWORD 1
  397. AddressFamily0 = REG_DWORD 2
  398. Protocol0 = REG_DWORD 2
  399. MinimumAddressLength0 = REG_DWORD 16
  400. MaximumAddressLength0 = REG_DWORD 16
  401. ProtocolAttributes0 = REG_DWORD 0x00001066
  402. ProtocolSocketDescription0 = REG_SZ "Stream socket in
  403. INET domain"
  404. SocketType1 = REG_DWORD 2
  405. AddressFamily1 = REG_DWORD 2
  406. Protocol1 = REG_DWORD 2
  407. MinimumAddressLength1 = REG_DWORD 16
  408. MaximumAddressLength1 = REG_DWORD 16
  409. ProtocolAttributes1 = REG_DWORD 0x00001609
  410.  
  411.      ProtocolSocketDescription1 = REG_DSZ "Dgram socket in
  412.      INET domain"
  413.      SocketType2 = REG_DWORD 3
  414.      AddressFamily2 = REG_DWORD 2
  415.      Protocol2 = REG_DWORD 2
  416.      MinimumAddressLength2 = REG_DWORD 16
  417.      MaximumAddressLength2 = REG_DWORD 16
  418.      ProtocolAttributes2 = REG_DWORD 0x00000109
  419.      ProtocolSocketDescription2 = REG_SZ"Raw socket in INET
  420.      domain"
  421.      
  422. The ProviderFilename value identifies the filename of the
  423. service provider DLL.
  424.  
  425. The ProviderDescription value is the descriptive text of
  426. this service provider.
  427.  
  428. The ProviderDomain value specifies the address family
  429. (defined in "ws2spi.h") this provider works with.
  430.  
  431. The ProviderAddrLength value is the (maximum) length of
  432. addresses (in bytes) used in the address family specified in
  433. ProviderDomain. The length includes the two-byte address
  434. family and the size of the address family specific address.
  435.  
  436. The NumSockets value indicates how many different types of
  437. sockets are supported, and how many SocketType<index>,
  438. AddressFamily<index>, Protocol<index>, and
  439. ProtocolSocketDescription<index> values appear in the
  440. section.
  441.  
  442. The SocketType<index> value (one per socket type) identifies
  443. the type of this socket as defined in "ws2spi.h".
  444.  
  445. The AddressFamily<index> value (one per socket type)
  446. identifies the address family of this socket as defined in
  447. "ws2spi.h".
  448.  
  449. The Protocol<index> value (one per socket type) identifies
  450. the protocol of this socket as defined in "ws2spi.h".
  451.  
  452. The MinimumAddressLength<index> value (one per socket type)
  453. specifies the minimum BYTE size of a valid address for this
  454. protocol.
  455.  
  456. The MaximumAddressLength<index> value (one per socket type)
  457. specifies the maximum BYTE size of a valid address for this
  458. protocol.
  459.  
  460. The ProtocolAttributes<index> value (one per socket type)
  461. identifies the behavioral characteristics of the protocol.
  462. This value consists of any number of XP_xxx values ORed
  463. together. (The XP_xxx values are defined in the Registration
  464. and Resolution API specification.)
  465.  
  466. The ProtocolSocketDescription<index> value (one per socket
  467. type) is the descriptive text for this protocolsocket.
  468.  
  469. In the SocketType<index>, AddressFamily<index>,
  470. Protocol<index>, and ProtocolSocketDescription<index>
  471. values, <index> takes the values from 0 to one less than
  472. <count> (as specified in NumSockets). These values are
  473. created by any software that installs the service provider.
  474. Although all these values must be present, there is no
  475. requirement that they appear in numerical order.
  476.  
  477. The service provider may include any other values/subkeys in
  478. its subkey which are necessary to fulfill the
  479. responsibilities of the provider as specified in the Winsock
  480. Service Provider Interface Specification, or for other
  481. private configuration purposes.
  482.  
  483. 2.1.2 WINSOCK2.INI Layout for Windows 3.1
  484.  
  485. The WINSOCK2.INI file contains a wide variety of
  486. information, and two kinds of identifiers are used:
  487.  
  488.   1.   name-sequence numbers. These numbers simply provide a
  489.      convenient way to index through a list of similar entries in
  490.      a WINSOCK2.INI file section. For example, the list of
  491.      "ProviderKey" entries in the [Providers] section uses the
  492.      names ProviderKey0, ProviderKey1, ProviderKey2, ... as a set
  493.      of easily-indexed names for the entries. The scope of these
  494.      name-sequence numbers is strictly limited to the section in
  495.      which they appear. These numbers are unrelated to anything
  496.      outside the section. They may be completely renumbered
  497.      whenever the WINSOCK2.INI configuration changes.
  498.      
  499.   2.   permanent string identifiers. These strings are
  500.      permanent identifiers for entries. They typically appear in
  501.      several different WINSOCK2.INI file sections to identify a
  502.      relationship between entries in those two sections. For
  503.      example, each provider-specific section ([Provider-<Provider
  504.      key>]) includes the permanent string identifier called
  505.      "provider key" of the provider in the section name. This
  506.      indicates that the entry corresponds to the service provider
  507.      with the matching permanent string identifier in the
  508.      [Providers] section. The scope of these string identifiers
  509.      includes the entire WINSOCK2.INI and persists until such
  510.      identifiers are explicitly changed. Some of these
  511.      identifiers can be retrieved through the Winsock SPI
  512.      interface.
  513.      
  514. 2.1.2.1 Providers
  515.  
  516. The "[Providers]" section of WINSOCK2.INI specifies the
  517. total number of the installed Winsock service providers, and
  518. the provider key for each service provider. This information
  519. is used so that Winsock2.DLL can identify and load each
  520. provider.
  521.  
  522. These entries in this section have the following format:
  523.  
  524.      [Providers]
  525.      NumProviders=<count>
  526.      ProviderKey<index>="<Provider Key>"
  527.      
  528. For example:
  529.  
  530.      [Providers]
  531.      NumProviders=2
  532.      ProviderKey0="novlwp"
  533.      ProviderKey1="FTP"
  534.      
  535. The NumProviders entry indicates how many service providers
  536. are installed, and how many ProviderKey<index> entries
  537. appear in the section. <count> is set to 0 when the Winsock
  538. implementation is initialized; the values are subsequently
  539. updated by any software that installs or removes service
  540. providers.
  541.  
  542. Each ProviderKey<index> entry (one per provider) specifies
  543. an unique provider key with which the service provider can
  544. identify itself. <index> takes the values from 0 to one less
  545. than <count> (as specified in NumProviders). The maximum
  546. length of the provider key is 32 characters. These entries
  547. are created by any software that installs service providers,
  548. and must be renumbered as providers are deleted. Although
  549. all these entries must be present, there is no requirement
  550. that they appear in numerical order. This provider key is
  551. also used to link parameters in other sections for provider-
  552. specific information.
  553.  
  554. 2.1.2.2   Provider-specific  Sections   ([Provider-<Provider
  555. Key>])
  556.  
  557. For each Winsock service provider defined in the [Providers]
  558. section, there must be a [Provider-<Provider Key>] section.
  559. The <Provider Key> value is the provider key defined for
  560. that service provider in the corresponding
  561. ProviderKey<index>="<Provider Key>" entry in the [Providers]
  562. section. For example, corresponding to an entry such as
  563. ProviderKey0="novlwp" there would be a section named
  564. [Provider-novlwp].
  565.  
  566. It is the responsibility of the service provider to create
  567. its provider-specific section in WINSOCK2.INI at the time it
  568. is installed. It is also the responsibility of the service
  569. provider to delete its provider-specific section in
  570. WINSOCK2.INI at the time it is removed. Only the service
  571. provider writes entries in its provider-specific section.
  572. Winsock2.DLL reads only the following entries in the
  573. provider-specific section. Other entries in the section are
  574. permitted for internal use by the service provider. This
  575. section consists, at a minimum, of the following:
  576.  
  577.      [Provider-<Provider Key>]
  578.      ProviderFilename="<filename>"
  579.      ProviderDescription="<Description of the provider>"
  580.       ProviderDomain=<Address family>
  581.      ProviderAddrLength=<length>
  582.      NumSockets=<count>
  583.      SocketType<index>=<Socket Type>
  584.      AddressFamily<index>=<Address Family>
  585.      Protocol<index>=<Protocol>
  586.      MinimumAddressLength<index>=<Minimum Address Length>
  587.      MaximumAddressLength<index>=<Maximum Address Length>
  588.      ProtocolAttributes<index>=<Protocol Attributes>
  589.      ProtocolSocketDescription<index>="<Description of the
  590.      protocolsocket>"
  591.      
  592. For example:
  593.  
  594.      [Provider-novlwp]
  595.      ProviderFilename="novlwp.WPSP"
  596.      ProviderDescription="Novell LAN WorkPlace for DOS"
  597.       ProviderDomain=2
  598.      ProviderAddrLength=8
  599.      NumSockets=3
  600.      SocketType0=1
  601.      AddressFamily0=2
  602.      Protocol0=2
  603.      MinimumAddressLength0 = 16
  604.      MaximumAddressLength0 = 16
  605.      ProtocolAttributes0 = 0x00001066
  606.      ProtocolSocketDescription0="Stream socket in INET
  607.      domain"
  608.      SocketType1=2
  609.      SocketDescription1="Dgram socket in INET domain"
  610.      SocketType2=3
  611.      MinimumAddressLength0 = 16
  612.      MaximumAddressLength0 = 16
  613.      ProtocolAttributes0 = 0x00001609
  614.      ProtocolSocketDescription2="Raw socket in INET domain"
  615.      
  616. The ProviderFilename entry identifies the filename of the
  617. service provider DLL.
  618.  
  619. The ProviderDescription entry is the descriptive text of
  620. this service provider.
  621.  
  622. The ProviderDomain entry specifies the address family
  623. (defined in "ws2spi.h") this provider works with.
  624.  
  625. The ProviderAddrLength entry is the (maximum) length of
  626. addresses (in bytes) used in the address family specified in
  627. ProviderDomain. The length includes the two-byte address
  628. family and the size of the address family specific address.
  629.  
  630. The NumSockets entry indicates how many different types of
  631. sockets are supported, and how many SocketType<index>,
  632. AddressFamily<index>, Protocol<index>, and
  633. ProtocolSocketDescription<index> entries appear in the
  634. section.
  635.  
  636. The SocketType<index> entry (one per socket type) identifies
  637. the type of this socket as defined in "ws2spi.h".
  638.  
  639. The AddressFamily<index> entry (one per socket type)
  640. identifies the address family of this socket as defined in
  641. "ws2spi.h".
  642.  
  643. The Protocol<index> entry (one per socket type) identifies
  644. the protocol of this socket as defined in "ws2spi.h".
  645.  
  646. The MinimumAddressLength<index> value (one per socket type)
  647. specifies the minimum BYTE size of a valid address for this
  648. protocol.
  649.  
  650. The MaximumAddressLength<index> value (one per socket type)
  651. specifies the maximum BYTE size of a valid address for this
  652. protocol.
  653.  
  654. The ProtocolAttributes<index> value (one per socket type)
  655. identifies the behavioral characteristics of the protocol.
  656. This value consists of any number of XP_xxx values ORed
  657. together. (The XP_xxx values are defined in the Registration
  658. and Resolution API specification.)
  659.  
  660. {Do we need to add a protocol entry as well so that all
  661. three components of the socket() call are represented?}
  662. Absolutely, yes. The omission is a PII artifact. We need
  663. every thing that goes into a PROTOCOL_INFO structstrct since
  664. the DLL implements WSAEnumProtocols() without help from the
  665. service provider itself. In fact, the service provider's DLL
  666. may well not have been loaded yet when WSAEnumProviers() is
  667. invoked, and we certainly do not want to requirereqire it to
  668. be loaded just to implement this function.
  669.  
  670. The ProtocolSocketDescription<index> entry (one per socket
  671. type) is the descriptive text for this protocolsocket.
  672.  
  673. In the SocketType<index>, AddressFamily<index>,
  674. Protocol<index>, and ProtocolSocketDescription<index>
  675. entiries, <index> takes the values from 0 to one less than
  676. <count> (as specified in NumSockets). These entries are
  677. created by any software that installs the service provider.
  678. Although all these entries must be present, there is no
  679. requirement that they appear in numerical order.
  680.  
  681. The service provider may include any other entries in its
  682. section which are necessary to fulfill the responsibilities
  683. of the provider as specified in the Winsock Service Provider
  684. Interface Specification, or for other private configuration
  685. purposes.
  686.  
  687. 2.2. Service Providers Interface Model
  688.  
  689. Winsock service providers are DLLs with EXPORTED procedure
  690. entry points for the functions defined by the SPI. Service
  691. providers should have their file extension changed from
  692. ".DLL" to ".WSP". This requirement is not strict. A service
  693. provider will still operate with the Winsock DLL with any
  694. file extension.
  695.  
  696. The SPI defines an entry point for each Winsock-specific
  697. function. These procedures are EXPORTED procedures just as
  698. in any DLL. They must be exported by ordinal numbers, as
  699. defined in "ws2spi.h" for each function. The Winsock DLL
  700. calls these Winsock specific entry points once the service
  701. provider is loaded using the standard dynamic linkage
  702. mechanism for calling DLLs.
  703.  
  704. Although entry points are required to be EXPORTED by name,
  705. loading entry points by name is time-consuming in some
  706. Windows environments.  The SPI includes a function to
  707. retrieve an entire table of SPI entry points, bypassing the
  708. name-oriented entry point loading.  The PII.DLL has the
  709. option of using PSGetProcTable() to load entry points in
  710. environments where this is a useful optimization.
  711. PSGetProcTable() retrieves all the functions defined by the
  712. SPI.
  713.  
  714. The entry points described above cover the instances in
  715. which the Winsock DLL invokes functions provided by the
  716. service provider. The SPI also defines several circumstances
  717. in which the service provider calls back into the Winsock
  718. DLL to inform the Winsock DLL of varioussome occurrences.
  719.  
  720. 2.3 Initialization of Winsock Service Providers
  721.  
  722. Over time, different versions may exist for the Winsock
  723. DLLs, applications, and service providers. New versions may
  724. define new features, new fields to data structures and bit
  725. fields, etc. Version numbers therefore indicate how to
  726. interpret various data structures.
  727.  
  728. To allow optimal mixing and matching of different versions
  729. of applications, versions of the Winsock DLL itself, and
  730. versions of service providers by different vendors, the SPI
  731. provides a version negotiation mechanism for the Winsock DLL
  732. and the service provider. This version negotiation is
  733. handled by WSPStartup(). Basically, the Winsock DLL passes
  734. to the service provider the highest version numbers it is
  735. compatible with. The service provider compares this with its
  736. own supported range of version numbers. If these ranges
  737. overlap, the service provider returns a value within the
  738. overlapping portion of the range as the result of the
  739. negotiation. Usually, this should be the highest possible
  740. value. If the ranges do not overlap, the two parties are
  741. incompatible and the function returns an error.
  742.  
  743. 2.4  Functionality  Implemented  WithinValue  Added  by  the
  744.    Winsock DLL
  745.  
  746. The major task that the Winsock DLL does is to serve as a
  747. sort of "traffic manager" between service providers and
  748. applications. Consider several different service providers
  749. interacting with the same application. Each Provider
  750. interacts strictly with the Winsock DLL. The Winsock DLL
  751. takes care of merging streams of events from those service
  752. providers into a single stream directed at the application.
  753. It hides the details of arbitration and synchronization over
  754. the data structures holding this single stream. Service
  755. providers are unaware that any of this is happening. They do
  756. not need to be concerned about the details of cooperating
  757. with one another or even the existence of other service
  758. providers. By abstracting the service providers into a
  759. consistent DLL interface, the Winsock DLL can interact with
  760. a variety of providers regardless of the underlying
  761. protocol's implementation technology.
  762.  
  763. In addition to its major "traffic manager" service, the
  764. Winsock DLL provides a number of other services such as
  765. socket descriptor management (in order to avoid conflicts
  766. and ambiguities between applications and service providers
  767. in order to avoid conflict and among service providers),
  768. parameter validation for Winsock API and Winsock SPI,
  769. version negotiation between applications and the Winsock
  770. DLL, as well as between the Winsock DLL and service
  771. providers. The Winsock DLL also realizes protocol
  772. enumeration, event objects, the shared sockets,
  773. implementation and and the pseudo blocking mechanism for
  774. Windows 3 environments.for any blocking Winsock function
  775. calls. Note that the differences between 16 and 32 bit
  776. versions of Windows with respect to blocking, preemption and
  777. shared address spaces dictates that the mechanisms used to
  778. implement the 16 and 32 bit versions of Winsock 2 DLLs vary
  779. significantly as well. This in turn leads to certain SPI
  780. functions that are applicable only to either 16 or 32 bit
  781. Windows implementations.
  782.  
  783. {It would be worthwhile to describe the routineg mechanism
  784. here. I.e., when an application invokes a socket-based API
  785. (such as bind()) how does the Winsock DLL route this request
  786. to the appropriate service provider?}
  787. { I agree that providing a simple example at this point would
  788. be most helpful }
  789.  
  790. 2.5   Functionality  ImplementedValue   Added   by   Service
  791. Providers
  792.  
  793. The Winsock DLL has no knowledge about how requests to
  794. service providers are realized; this is up to the service
  795. provider implementation. Service providers implement the
  796. actual transport protocol which includes such functions as
  797. support the low-level network-specific aspects of Winsock.
  798. This includes functions such as setting up connections,
  799. transferring data, exercising flow control and error
  800. control, etc. The implementation of such functions may
  801. differs greatly from one provider to another. Service
  802. providers hide the implementation-specific details of how
  803. network operations are accomplished.
  804.  
  805. To summarize: service providers implement provide the low-
  806. level network-specific protocolsmechanisms. The Winsock DLL
  807. provides the medium-level traffic management that
  808. interconnects these transport protocols mechanisms with
  809. applications. Applications in turn provide the policy of how
  810. these traffic streams and network-specific operations are
  811. used to accomplish the functions desired by the user.
  812.  
  813. 2.6 Differences and Similarities Between Winsock API and SPI
  814.  
  815. The Winsock SPI is similar to the Winsock API in that all
  816. the basic socket functions appear. Support functions like
  817. htonl(), htons(), ntohl(), ntohs(), inet_addr(), and
  818. inet_ntoa() are implemented in the Winsock DLL, and are not
  819. passed down to SPI.
  820.  
  821. If an extended version of a function and the original
  822. version of a function both exist in the API, only the
  823. extended version will show up in the SPI. For example,
  824. connect() and WSAConnect() will both map to WSPConnect(),
  825. accept() and WSAAccept() to WSPAccept(), and socket() and
  826. WSASocket() to WSPSocket().
  827.  
  828. Since error codes are returned along with SPI functions,
  829. equivalents of WSAGetLastError() and WSASetLastError() are
  830. not needed in the SPI.
  831.  
  832. Shared sockets, socket group member enumeration, and Winsock
  833. service provider enumeration are bothall realized in the
  834. Winsock DLL, thus WSADuplicateSocket(), WSAEnumGroup(), and
  835. WSAEnumProtocolsProviders() do not appear as SPI functions.
  836.  
  837. 2.7 Differences Between 32-bit and 16-bit Winsock SPI
  838.  
  839. In 32-bit environments the service providers are responsible
  840. for implementing blocking behavior. All blocking hook
  841. related API functions such as WSAIsBlocking(),
  842. WSACancelBlockingCall(), WSASetBlockingHook(), and
  843. WSAUnhookBlockingHook() appear in SPI. All event object
  844. related API functions are implemented as #define macros,
  845. mapping the Winsock event functions to native Win32 event
  846. functions.
  847.  
  848. In 16-bit environments the Winsock DLL implements all
  849. blocking behavior (as pseudopsuedo blocking), and all SPI
  850. sockets are strictly non-blocking. All the blocking hook
  851. related API functions such as WSAIsBlocking(),
  852. WSACancelBlockingCall(), WSASetBlockingHook(), and
  853. WSAUnhookBlockingHook() dowill not appear in the 16 bit SPI
  854. because the blocking hook implementation iswill be realized
  855. in Winsock2.DLL. Similarly, all the event object related API
  856. functions are also implemented in Winsock2.DLL, e.g.,
  857. WSACreateEvent(), WSACloseEvent(), WSASetEvent(),
  858. WSAResetEvent(), WSAWaitForMultipleEvents(), and
  859. WSAGetOverlappedResult().
  860.  
  861. 2.8 Sockets 2.8 Sockets
  862.  
  863. See API spec for intorductory text on sockets.
  864.  
  865. 2.8.1 Socket Types
  866.  
  867. See the API for information on socket types.
  868.  
  869. 2.8.21 Out-of-band data
  870.  
  871. Note: The following discussion of out-of-band data, also
  872. referred to as TCP Urgent data, follows the model used in
  873. the Berkeley software distribution. Users and implementors
  874. should be aware of the fact that there are at present two
  875. conflicting interpretations of RFC 793 (in which the concept
  876. is introduced), and that the implementation of out-of-band
  877. data in the Berkeley Software Distribution does not conform
  878. to the Host Requirements laid down in RFC 1122. To minimize
  879. interoperability problems, applications writers are advised
  880. not to use out-of-band data unless this is required in order
  881. to interoperate with an existing service. Winsock suppliers
  882. are urged to document the out-of-band semantics (BSD or RFC
  883. 1122) which their product implements. It is beyond the scope
  884. of this specification to mandate a particular set of
  885. semantics for out-of-band data handling.
  886.  
  887. Note that the out-of-band data functionality is mainly
  888. inherited from the TCP/IP world, and may not be available to
  889. other communication domains supported by this specification.
  890.  
  891. The stream socket abstraction includes the notion of "out of
  892. band'' data. Out-of-band data is a logically independent
  893. transmission channel associated with each pair of connected
  894. stream sockets. Out-of-band data is delivered to the user
  895. independently of normal data. The abstraction defines that
  896. the out-of-band data facilities must support the reliable
  897. delivery of at least one out-of-band message at a time. This
  898. message may contain at least one byte of data, and at least
  899. one message may be pending delivery to the user at any one
  900. time. For communications protocols which support only in-
  901. band signaling (i.e., the urgent data is delivered in
  902. sequence with the normal data), the system normally extracts
  903. the data from the normal data stream and stores it
  904. separately. This allows users to choose between receiving
  905. the urgent data in order and receiving it out of sequence
  906. without having to buffer all the intervening data. It is
  907. possible to "peek'' at out-of-band data.
  908.  
  909. An application may prefer to process out-of-band data "in-
  910. line", as part of the normal data stream. This is achieved
  911. by setting the socket option SO_OOBINLINE (see section
  912. 3.1.3.1.3.1., WSPSetSockOptWSPsetsockopt()). In this case,
  913. the application may wish to determine whether any of the
  914. unread data is "urgent" (the term usually applied to in-line
  915. out-of-band data). To facilitate this, the Winsock service
  916. provider will maintain a logical "mark" in the data stream
  917. to indicate the point at which the out-of-band data was
  918. sent. An application can use the SIOCATMARK
  919. WSPIoctlSocketWSPioctlsocket() command (see section
  920. 3.1.63.1.63.1.6) to determine whether there is any unread
  921. data preceding the mark. For example, it might use this to
  922. resynchronize with its peer by ensuring that all data up to
  923. the mark in the data stream is discarded when appropriate.
  924.  
  925. 2.8.3 Broadcasting
  926.  
  927. See the API spec for information on Winsock 2's support for
  928. broadcasting
  929.  
  930. 2.8.42 Socket Options
  931.  
  932. The socket options supported by Winsock SPI are listed and
  933. described in the pages describing
  934. WSPSetSockOptWSPsetsockopt() and
  935. WSPGetSockOptWSPgetsockopt(). A summary of the available
  936. options and the default value for each is shown in the
  937. following table.
  938.  
  939. Value            Type    Meaning            Default     Not
  940.                                                         e
  941. SO_ACCEPTCONN    BOOL    Socket is          FALSE       get
  942.                          WSPListenWSPliste  unless a    onl
  943.                          n()ing.            WSPListenW  y
  944.                                             SPlisten()
  945.                                             has been
  946.                                             performed
  947. SO_BROADCAST     BOOL    Socket is          FALSE       (i)
  948.                          configured for
  949.                          the transmission
  950.                          of broadcast
  951.                          messages.
  952. SO_DEBUG         BOOL    Debugging is       FALSE       (i)
  953.                          enabled.
  954. SO_DONTLINGER    BOOL    If true, the       TRUE        
  955.                          SO_LINGER option
  956.                          is disabled.
  957. SO_DONTROUTE     BOOL    Routing is         FALSE       (i)
  958.                          disabled.
  959. SO_FLOWSPEC      char    The flow spec of   NULL        get
  960.                  FAR *   this socket.                   onl
  961.                                                         y
  962. SO_GROUP_FLOWSP  char    The flow spec of   NULL        get
  963. EC               FAR *   the socket group               onl
  964.                          to which this                  y
  965.                          socket belongs.
  966. SO_GROUP_ID      GROUP   The identifier of  NULL        get
  967.                          the group to                   onl
  968.                          which this socket              y
  969.                          belongs.
  970. SO_GROUP_PRIORI  int     The relative       0           (i)
  971. TY                       priority for
  972.                          sockets that are
  973.                          part of a socket
  974.                          group.
  975. SO_KEEPALIVE     BOOL    Keepalives are     FALSE       (i)
  976.                          being sent.
  977. SO_LINGER        struct  Returns the        l_onoff is  
  978.                  linger  current linger     0
  979.                          options.
  980. SO_MAX_MSGDG_SI  unsign  Maximum size of a  Implementa  get
  981. ZE               ed int  message for        tion        onl
  982.                          message-oriented   dependent   y
  983.                          socket types
  984.                          (e.g. DGRAM and
  985.                          DSTREAM). Has no
  986.                          meaning for
  987.                          stream-oriented
  988.                          sockets.
  989. SO_OOBINLINE     BOOL    Out-of-band data   FALSE       
  990.                          is being received
  991.                          in the normal
  992.                          data stream.
  993. SO_PROTOCOL_INF  struct  Description of     Protocol    get
  994. O                PROTOC  protocol info for  dependent   onl
  995.                  OL_INF  protocol that is               y
  996.                  O       bound to this
  997.                          socket.
  998. SO_RCVBUF        int     Buffer size for    Implementa  (i)
  999.                          receives           tion
  1000.                                             dependent
  1001. SO_REUSEADDR     BOOL    The address to     FALSE       
  1002.                          which this socket
  1003.                          is bound can be
  1004.                          used by others.
  1005. SO_SNDBUF        int     Buffer size for    Implementa  (i)
  1006.                          sends              tion
  1007.                                             dependent
  1008. SO_TYPE          int     The type of the    As created  get
  1009.                          socket (e.g.       via         onl
  1010.                          SOCK_STREAM).      WSPSsocket  y
  1011.                                             ()
  1012. PVD_CONFIG       char    An opaque data     Implementa  
  1013.                  FAR *   structure object   tion
  1014.                          containing         dependent
  1015.                          configuration
  1016.                          information of
  1017.                          the service
  1018.                          provider.
  1019. TCP_NODELAY      BOOL    Disables the       Implementa  
  1020.                          Nagle algorithm    tion
  1021.                          for send           dependent
  1022.                          coalescing.
  1023.  
  1024. Notes:
  1025. (i)       An implementation may silently ignore this option
  1026.           on WSPSetSockOptWSPsetsockopt() and return a
  1027.           constant value for WSPGetSockOptWSPgetsockopt(),
  1028.           or it may accept a value for
  1029.           WSPSetSockOptWSPsetsockopt() and return the
  1030.           corresponding value in
  1031.           WSPGetSockOptWSPgetsockopt() without using the
  1032.           value in any way.
  1033.  
  1034. 2.9 Quality of Service (QOS)
  1035. 2.9.1 Overall Approach
  1036.  
  1037. The basic QOS mechanism in Winsock descends from the flow
  1038. specification (or "flow spec") as described by Craig
  1039. Partridge in RFC 1363, dated September 1992. A brief
  1040. overview of this concept is as follows:
  1041.  
  1042.  Flow specs describe a set of characteristics about a
  1043. proposed connection-oriented, unidirectional flow through
  1044. the network. An application may associate a pair of flow
  1045. specs with a socket at the time a connection request is
  1046. made. Flow specs indicate parametrically what level of
  1047. service is required and also stipulate whether the
  1048. application is willing to be flexible if the requested level
  1049. of service is not available. After a connection is
  1050. established, the application may retrieve the flow specs
  1051. associated with the socket and examine the contents to
  1052. discover the level of service that the network is willing
  1053. and/or able to provide. If the service provided is not
  1054. acceptable, the application may close the socket and take
  1055. whatever action is appropriate (e.g. scale back and ask for
  1056. a lower quality of service, try again later, notify the user
  1057. and exit, etc.)
  1058.  
  1059. Even after a flow is established, conditions in the network
  1060. may change resulting in a reduction (or increase) in the
  1061. available service level. A notification mechanism is
  1062. included which utilizes the usual Winsock 2 notification
  1063. techniques to indicate to the application that QOS levels
  1064. have changed. The app should again retrieve the
  1065. corresponding flow specs and examine them in order to
  1066. discover what aspect of the service level has changed.
  1067.  
  1068. The flow specs proposed for Winsock 2 divide QOS
  1069. characteristics into the following general areas:
  1070.  
  1071. 1.Network bandwidth utilization - The manner in which the
  1072.   application's traffic will be injected into the network.
  1073.   This includes specifications for average bandwidth
  1074.   utilization, peak bandwidth, and maximum burst duration.
  1075.  
  1076. 2.Latency - Upper limits on the amount of delay and delay
  1077.   variation that are acceptable.
  1078.  
  1079. 3.Level of service guarantee - Whether or not an absolute
  1080.   guarantee is required as opposed to best effort. Note
  1081.   that providers which have no feasible way to provide the
  1082.   level of service requestedrequeted are expected to fail
  1083.   the connection attempt.
  1084.  
  1085. 4.Cost - This is a place holder for a future time when a
  1086.   meaningful cost metric can be determined.
  1087.  
  1088. 5.Provider-specific parameters - The flow spec itself can
  1089.   be extended in ways that are particular to specific
  1090.   providers, and the assumed provider can be identified.
  1091.  
  1092.  
  1093. An application indicates its desire for a non-default flow
  1094. spec at the time a connection request is made (see
  1095. WSPConnect () and WSPAccept()). Since establishing a flow
  1096. spec'd connection is likely to involve cooperation and/or
  1097. negotiation between intermediate routers and hosts, the
  1098. results of a flow spec request cannot be determined until
  1099. after the connection operation is fully completed. After
  1100. this time, the application may use getsockopt() to retrieve
  1101. the resulting flow spec structure so that it can determine
  1102. what the network was willing and/or able to supply.
  1103.  
  1104. 2.9.2 The Flow Spec Structure
  1105.  
  1106. The Winsock 2 flow spec structure is defined in Winsock2.h
  1107. and is reproduced here.
  1108.  
  1109. typedef enum
  1110. {
  1111.      GuaranteedService,
  1112.      BestEffortService
  1113. } GUARANTEE;
  1114.  
  1115. typedef struct _flowparams
  1116. {
  1117.      int64          AverageBandwith;// In Bytes/sec
  1118.      int64          PeakBandwidth; // In Bytes/sec
  1119.      int64          BurstLength;   // In microseconds
  1120.      int64          Latency;  // In microseconds
  1121.      int64          DelayVariation;// In microseconds
  1122.      GUARANTEE levelOfGuarantee;// Guaranteed or
  1123.                          // Best Effort
  1124.      int32          CostOfCall;    // Reserved for future
  1125.                          // use, must be set to 0
  1126.      int32          ProviderId;    // Provider Identifier
  1127.      int32          SizePSP;  // Length of provider
  1128.                          // specific parameters
  1129.           UCHAR     ProviderSpecificParams[1];// provider
  1130. specific                                          //
  1131. parameters
  1132. } FLOWPARAMS;
  1133.  
  1134. typedef struct _QualityOfService
  1135. {
  1136.      FLOWPARAMS     ForwardFP;     // Caller(Initiator) to
  1137. callee
  1138.      FLOWPARAMS     BackwardFP;    // Callee to caller
  1139. } QOS, FAR * LPQOS;
  1140. 3. SERVICE PROVIDER INTERFACE REFERENCE
  1141.  
  1142. 3.1 Socket Routines
  1143.  
  1144. This chapter presents the service provider socket library
  1145. routines in alphabetical order, and describes each routine
  1146. in detail.
  1147. { Since the SPI is new, I propose that we do not have
  1148. separate sections for Windows-specific extensions}
  1149.  
  1150. In each routine it is indicated that the header file
  1151. ws2spi.h must be included. Appendix A.2 lists the Berkeley-
  1152. compatible header files which are supported.  These are
  1153. provided for compatibility purposes only, and each of them
  1154. will simply include PII.h. The Windows header file windows.h
  1155. is also needed, but ws2spi.h will include it if necessary.
  1156. 3.1.1 PSaccept()
  1157. Description    Accept a connection on a socket.
  1158.  
  1159.           #include <PIISPI.h>
  1160.  
  1161.           SOCKET PASCAL FAR PSaccept ( SOCKET s, struct
  1162.           sockaddr FAR * addr,
  1163.           int FAR * addrlen, int FAR * lpErrno );
  1164.  
  1165.           
  1166.           s          A descriptor identifying a socket which
  1167.                     is listening for connections after a
  1168.                     PSlisten().
  1169.           
  1170.           addr      An optional pointer to a buffer which
  1171.                     receives the address of the connecting
  1172.                     entity, as known to the communications
  1173.                     layer.  The exact format of the addr
  1174.                     argument is determined by the address
  1175.                     family established when the socket was
  1176.                     created.
  1177.           
  1178.           addrlen   An optional pointer to an integer which
  1179.                     contains the length of the address addr.
  1180.           
  1181.           lpErrno   A pointer to the error code.
  1182.  
  1183. Remarks   This routine extracts the first connection on the
  1184.           queue of pending connections on s, creates a new
  1185.           socket with the same properties as s except not in
  1186.           the listening state, and returns a handle to the
  1187.           new socket.  If no pending connections are present
  1188.           on the queue, and the socket is not marked as non-
  1189.           blocking, PSaccept() blocks the caller until a
  1190.           connection is present.  If the socket is marked
  1191.           non-blocking and no pending connections are
  1192.           present on the queue, PSaccept() returns an error
  1193.           as described below.  The accepted socket may not
  1194.           be used to accept more connections.  The original
  1195.           socket remains open.
  1196.  
  1197.           The argument addr is a result parameter that is
  1198.           filled in with the address of the connecting
  1199.           entity, as known to the communications layer.  The
  1200.           exact format of the addr parameter is determined
  1201.           by the address family in which the communication
  1202.           is occurring.  The addrlen is a value-result
  1203.           parameter; it should initially contain the amount
  1204.           of space pointed to by addr; on return it will
  1205.           contain the actual length (in bytes) of the
  1206.           address returned.  This call is used with
  1207.           connection-oriented socket types such as
  1208.           SOCK_STREAM.  If addr and/or addrlen are equal to
  1209.           NULL, then no information about the remote address
  1210.           of the accepted socket is returned.
  1211.  
  1212. Return Value   If no error occurs, PSaccept() returns a
  1213.           value of type SOCKET which is a descriptor for the
  1214.           accepted packet.  Otherwise, a value of
  1215.           INVALID_SOCKET is returned, and a specific error
  1216.           code is available in lpErrno.
  1217.  
  1218.           The integer referred to by addrlen initially
  1219.           contains the amount of space pointed to by addr.
  1220.           On return it will contain the actual length in
  1221.           bytes of the address returned.
  1222.  
  1223. Error Codes                   WSANOTINITIALISED   A
  1224.                               successful PSStartup() must
  1225.                               occur before using this SPI.
  1226.           
  1227.           WSAENETDOWN         The network subsystem has
  1228.                               failed.
  1229.           
  1230.           WSAEFAULT           The addrlen argument is too
  1231.                               small (less than the sizeof a
  1232.                               struct sockaddr).
  1233.           
  1234.           WSAEINTR            The (blocking) call was
  1235.                               canceled via
  1236.                               PSCancelBlockingCall().
  1237.           
  1238.           WSAEINPROGRESS      A blocking PII call is in
  1239.                               progress.
  1240.           
  1241.           WSAEINVAL           PSlisten() was not invoked
  1242.                               prior to PSaccept().
  1243.           
  1244.           WSAEMFILE           The queue is non-empty upon
  1245.                               entry to PSaccept() and there
  1246.                               are no descriptors available.
  1247.           
  1248.           WSAENOBUFS          No buffer space is available.
  1249.           
  1250.           WSAENOTSOCK         The descriptor is not a
  1251.                               socket.
  1252.           
  1253.           WSAEOPNOTSUPP       The referenced socket is not a
  1254.                               type that supports connection-
  1255.                               oriented service.
  1256.           
  1257.           WSAEWOULDBLOCK      No connections are present to
  1258.                               be accepted.
  1259.           
  1260. See Also  PSbind(), PSconnect(), PSlisten(), PSselect(),
  1261.           PSsocket(), PSCallbackSelect()
  1262.  
  1263. 3.1.1 WSPBindWSPbind()
  1264.  
  1265. Description    Associate a local address with a socket.
  1266.  
  1267.           #include <ws2spi.h>
  1268.  
  1269.           int WSPAPI WSPBindWSPbind ( SOCKET s, const struct
  1270.           sockaddr FAR * name, int namelen, int FAR *
  1271.           lpErrno );
  1272.  
  1273.           
  1274.           s          A descriptor identifying an unbound
  1275.                     socket.
  1276.           
  1277.           name      The address to assign to the socket. The
  1278.                     sockaddr structure is defined as
  1279.                     follows:
  1280.           
  1281.                     struct sockaddr {
  1282.                          u_short   sa_family;
  1283.                          char      sa_data[14];
  1284.                     };
  1285.           
  1286.           namelen   The length of the name.
  1287.           
  1288.           lpErrno   A pointer to the error code.
  1289.  
  1290. Remarks   This routine is used on an unconnected
  1291.           connectionless or connection-oriented socket,
  1292.           before subsequent WSPConnect()s or
  1293.           WSPListenWSPlisten()s. When a socket is created
  1294.           with WSPsocket(), it exists in a name space
  1295.           (address family), but it has no name assigned.
  1296.           WSPBindWSPbind() establishes the local association
  1297.           of the socket by assigning a local name to an
  1298.           unnamed socket.
  1299.           
  1300.           As an example, in the Internet address family, a
  1301.           name consists of three parts: the address family,
  1302.           a host address, and a port number which identifies
  1303.           the application. In Winsock 2, the name parameter
  1304.           is not strictly interpreted as a pointer to a
  1305.           "sockaddr" struct. It is cast this way for Windows
  1306.           Sockets 1.1 compatibility. Service providers are
  1307.           free to regard it as a pointer to a block of
  1308.           memory of size namelen. The first two bytes in
  1309.           this block (corresponding to "sa_family" in the
  1310.           "sockaddr" declaration) must contain the address
  1311.           family that was used to create the socket.
  1312.           Otherwise an error WSAEFAULT will occur.
  1313.           
  1314. Return Value   If no error occurs, WSPBindWSPbind() returns
  1315.           0. Otherwise, it returns SOCKET_ERROR, and a
  1316.           specific error code is available in lpErrno.
  1317.  
  1318. Error Codes                   WSANOTINITIALISED   A
  1319.                               successful PSStartup() must
  1320.                               occur before using this SPI.
  1321.           
  1322.           WSAENETDOWN         The network subsystem has
  1323.                               failed.
  1324.           
  1325.           WSAEADDRINUSE       The specified address is
  1326.                               already in use. (See the
  1327.                               SO_REUSEADDR socket option
  1328.                               under
  1329.                               WSPSetSockOptWSPsetsockopt().)
  1330.           
  1331.           WSAEFAULT           The namelen argument is too
  1332.                               small (less than the size of a
  1333.                               struct sockaddr), the name
  1334.                               argument contains incorrect
  1335.                               address format for the
  1336.                               associated address family, or
  1337.                               the first two bytes of the
  1338.                               memory block specified by name
  1339.                               does not match the address
  1340.                               family associate with the
  1341.                               socket descriptor s.
  1342.           
  1343.           WSAEINPROGRESS      The function is invoked when a
  1344.                               callback is in progress.
  1345.           
  1346.           WSAEAFNOSUPPORT     The specified address family
  1347.                               is not supported by this
  1348.                               protocol.
  1349.           
  1350.           WSAEINVAL           The socket is already bound to
  1351.                               an address.
  1352.           
  1353.           WSAENOBUFS          Not enough buffers available,
  1354.                               too many connections.
  1355.           
  1356.           WSAENOTSOCK         The descriptor is not a
  1357.                               socket.
  1358.  
  1359. See Also  WSPConnect(), WSPListenWSPlisten(),
  1360.           WSPGetSockNameWSPgetsockname(),
  1361.           WSPSetSockOptWSPsetsockopt(), WSPsocket(),
  1362.           PSCancelBlockingCall().
  1363. 3.1.2 WSPCloseSocketWSPclosesocket()
  1364.  
  1365. Description    Close a socket.
  1366.  
  1367.           #include <ws2spi.h>
  1368.  
  1369.           int WSPAPI WSPCloseSocketWSPclosesocket ( SOCKET
  1370.           s, int FAR * lpErrno );
  1371.  
  1372.           
  1373.           s          A descriptor identifying a socket.
  1374.           
  1375.           lpErrno   A pointer to the error code.
  1376.  
  1377. Remarks   This function closes a socket. More precisely, it
  1378.           releases the socket descriptor s, so that further
  1379.           references to s will fail with the error
  1380.           WSAENOTSOCK.  If this is the last reference to an
  1381.           underlying socket, the associated naming
  1382.           information and queued data are discarded.
  1383.           
  1384.           The semantics of WSPCloseSocketWSPclosesocket()
  1385.           are affected by the socket options SO_LINGER and
  1386.           SO_DONTLINGER as follows:
  1387.  
  1388.           Option         Interval       Type of close  Wait
  1389.                     for close?
  1390.           SO_DONTLINGER  Don't care     Graceful       No
  1391.           SO_LINGER      Zero      Hard      No
  1392.           SO_LINGER      Non-zero  Graceful       Yes
  1393.  
  1394.           If SO_LINGER is set (i.e. the l_onoff field of the
  1395.           linger structure is non-zero; see sections
  1396.           3.1.53.1.53.1.5 and 3.1.3.1.3.1.) with a zero
  1397.           timeout interval (l_linger is zero),
  1398.           WSPCloseSocketWSPclosesocket() is not blocked even
  1399.           if queued data has not yet been sent or
  1400.           acknowledged. This is called a "hard" or
  1401.           "abortive" close, because the socket's virtual
  1402.           circuit is reset immediately, and any unsent data
  1403.           is lost. Any WSPRecvWSPrecv() call on the remote
  1404.           side of the circuit will fail with WSAECONNRESET.
  1405.           
  1406.           If SO_LINGER is set with a non-zero timeout
  1407.           interval, the PSclosesocket() call blocks until
  1408.           the remaining data has been sent or until the
  1409.           timeout expires.  This is called a graceful
  1410.           disconnect.  Note that if the socket is set to non-
  1411.           blocking and SO_LINGER is set to a non-zero
  1412.           timeout, the call to PSclosesocket() will fail
  1413.           with an error of WSAEWOULDBLOCK.
  1414.  
  1415.           If SO_DONTLINGER is set on a stream socket (i.e.
  1416.           the l_onoff field of the linger structure is zero;
  1417.           see sections 3.1.53.1.53.1.5 and 3.1.3.1.3.1.),
  1418.           the WSPCloseSocketWSPclosesocket() call will
  1419.           return immediately. However, any data queued for
  1420.           transmission will be sent if possible before the
  1421.           underlying socket is closed. This is also called a
  1422.           graceful disconnect. Note that in this case the
  1423.           Winsock service provider may not release the
  1424.           socket and other resources for an arbitrary
  1425.           period, which may affect applications which expect
  1426.           to use all available sockets.
  1427.  
  1428. Return Value   If no error occurs,
  1429.           WSPCloseSocketWSPclosesocket() returns 0.
  1430.           Otherwise, a value of SOCKET_ERROR is returned,
  1431.           and a specific error code is available in lpErrno.
  1432.           
  1433. Error Codes                   WSANOTINITIALISED   A
  1434.                               successful PSStartup() must
  1435.                               occur before using this SPI.
  1436.           
  1437.           WSAENETDOWN         The network subsystem has
  1438.                               failed.
  1439.           
  1440.           WSAEINPROGRESS      The function is invoked when a
  1441.                               callback is in progress.
  1442.           
  1443.           WSAENOTSOCK         The descriptor is not a
  1444.                               socket.
  1445.           
  1446. See Also  WSPAccept, WSPsocket(),
  1447.           WSPIoctlSocketWSPioctlsocket(),
  1448.           WSPSetSockOptWSPsetsockopt().
  1449. 3.1.4 PSconnect()
  1450. Description    Establish a connection to a peer.
  1451.  
  1452.           #include <PIISPI.h>
  1453.  
  1454.           int PASCAL FAR PSconnect ( SOCKET s, const struct
  1455.           sockaddr FAR * name,
  1456.           int namelen, int FAR * lpErrno );
  1457.  
  1458.           
  1459.           s          A descriptor identifying an unconnected
  1460.                     socket.
  1461.           
  1462.           name      The name of the peer to which the socket
  1463.                     is to be connected.
  1464.           
  1465.           namelen   The length of the name.
  1466.           
  1467.           lpErrno   A pointer to the error code.
  1468.  
  1469. Remarks   This function is used to create a connection to
  1470.           the specified destination.  For connection-
  1471.           oriented sockets (e.g., type SOCK_STREAM), an
  1472.           active connection is initiated to the foreign host
  1473.           using name (an address in the name space of the
  1474.           socket; for a detailed description, please see
  1475.           PSbind()).  When the socket call completes
  1476.           successfully, the socket is ready to send/receive
  1477.           data.
  1478.           
  1479.           For a connectionless socket (e.g., type
  1480.           SOCK_UNREL_DGRAM), the operation performed by
  1481.           PSconnect() is merely to establish a default
  1482.           destination address which will be used on
  1483.           subsequent PSsend() and PSrecv() calls.
  1484.           
  1485.           If the socket, s, is unbound, unique values are
  1486.           assigned to the local association by the system,
  1487.           and the socket is marked as bound.  Note that if
  1488.           the address field of the name structure is all
  1489.           zeroes, PSconnect() will return the error
  1490.           WSAEADDRNOTAVAIL.
  1491.           
  1492.  
  1493. Return Value   If no error occurs, PSconnect() returns 0.
  1494.           Otherwise, it returns SOCKET_ERROR, and a specific
  1495.           error code is available in lpErrno.
  1496.  
  1497.           On a non-blocking socket,If the return value is
  1498.           SOCKET_ERROR an application should call
  1499.           PSGetLastError().  For connection-oriented
  1500.           sockets, if the return value is 0, indicating the
  1501.           connect operation has been successfully initiated,
  1502.           then your application can either:
  1503.           
  1504.           1. Use PSselect() to determine the completion of
  1505.           the connection request by checking if the socket
  1506.           is writeable,  or
  1507.           
  1508.           2. If your application is using PSCallbackSelect()
  1509.           to indicate interest in connection events, then
  1510.           your application will receive an FD_CONNECT
  1511.           callback when the connect operation is complete.
  1512.  
  1513. Error Codes    The following errors may occur at the time of
  1514.           the function call, and indicate that the connect
  1515.           operation could not be initiated.
  1516.  
  1517. WSANOTINITIALISED             A successful PSStartup() must
  1518.                               occur before using this SPI.
  1519.           
  1520.           WSAENETDOWN         The network subsystem has
  1521.                               failed.
  1522.           
  1523.           WSAEADDRINUSE       The specified address is
  1524.                               already in use.
  1525.           
  1526.           WSAEINTR            The (blocking) call was
  1527.                               canceled via
  1528.                               PSCancelBlockingCall().
  1529.           
  1530.           WSAEINPROGRESS      A blocking PII call is in
  1531.                               progress.
  1532.           
  1533.           WSAEADDRNOTAVAIL    The specified address is not
  1534.                               available from the local
  1535.                               machine.
  1536.           
  1537.           WSAEAFNOSUPPORT     Addresses in the specified
  1538.                               family cannot be used with
  1539.                               this socket.
  1540.           
  1541.           WSAEDESTADDREQ      A destination address is
  1542.                               required.
  1543.           
  1544.           WSAEFAULT           The namelen argument is
  1545.                               incorrect.
  1546.           
  1547.           WSAEINVAL           The socket is not already
  1548.                               bound to an address.
  1549.           
  1550.           WSAEISCONN          The socket is already
  1551.                               connected.
  1552.           
  1553.           WSAEMFILE           No more socket descriptors are
  1554.                               available.
  1555.           
  1556.           WSAENETUNREACH      The network can't be reached
  1557.                               from this host at this time.
  1558.           
  1559.           WSAENOBUFS          No buffer space is available.
  1560.                               The socket cannot be
  1561.                               connected.
  1562.           
  1563.           WSAENOTSOCK         The descriptor is not a
  1564.                               socket.
  1565.           
  1566.           WSAEWOULDBLOCK      The socket is marked as non-
  1567.                               blocking and the connection
  1568.                               cannot be completed
  1569.                               immediately.  It is possible
  1570.                               to PSselect() the socket while
  1571.                               it is connecting by
  1572.                               PSselect()ing it for writing.
  1573.  
  1574.  
  1575.           The following error codes may be set when the
  1576.           callback function is invoked.
  1577.  
  1578. WSANOTINITIALISED             A successful PSStartup() must
  1579.                               occur before using this SPI.
  1580.           
  1581.           WSAENETDOWN         The network subsystem has
  1582.                               failed.
  1583.           
  1584.           WSAEADDRINUSE       The specified address is
  1585.                               already in use.
  1586.           
  1587.           WSAEINTR            The (blocking) call was
  1588.                               canceled via
  1589.                               PSCancelBlockingCall().
  1590.           
  1591.           WSAEINPROGRESS      A blocking PII call is in
  1592.                               progress.
  1593.           
  1594.           WSAEADDRNOTAVAIL    The specified address is not
  1595.                               available from the local
  1596.                               machine.
  1597.           
  1598.           WSAEAFNOSUPPORT     Addresses in the specified
  1599.                               family cannot be used with
  1600.                               this socket.
  1601.           
  1602.           WSAECONNREFUSED     The attempt to connect was
  1603.                               forcefully rejected.
  1604.           
  1605.           WSAENETUNREACH      The network can't be reached
  1606.                               from this host at this time.
  1607.           
  1608.           WSAENOBUFS          No buffer space is available.
  1609.                               The socket cannot be
  1610.                               connected.
  1611.           
  1612.           WSAETIMEDOUT        Attempt to connect timed out
  1613.                               without establishing a
  1614.                               connection
  1615.           
  1616. See Also  PSaccept(), PSbind(), PSgetsockname(), PSsocket(),
  1617.           PSselect()PSCallbackSelect(), PSConnectEx().
  1618. 3.1.3 WSPGetPeerNameWSPgetpeername()
  1619.  
  1620. Description    Get the address of the peer to which a socket
  1621.           is connected.
  1622.  
  1623.           #include <ws2spi.h>
  1624.  
  1625.           int WSPAPI WSPGetPeerNameWSPgetpeername ( SOCKET
  1626.           s, struct sockaddr FAR * name, int FAR * namelen,
  1627.           int FAR * lpErrno );
  1628.  
  1629.           
  1630.           s          A descriptor identifying a connected
  1631.                     socket.
  1632.           
  1633.           name      The structure which is to receive the
  1634.                     name of the peer.
  1635.           
  1636.           namelen   A pointer to the size of the name
  1637.                     structure.
  1638.           
  1639.           lpErrno   A pointer to the error code.
  1640.  
  1641. Remarks   WSPGetPeerNameWSPPSgetpeername() retrieves the
  1642.           name of the peer connected to the socket s and
  1643.           stores it in the struct sockaddr identified by
  1644.           name. It is used on a connected datagram or stream
  1645.           socket.
  1646.  
  1647.           On return, the namelen argument contains the
  1648.           actual size of the name returned in bytes.
  1649.  
  1650. Return Value   If no error occurs,
  1651.           WSPGetPeerNameWSPgetpeername() returns 0.
  1652.           Otherwise, a value of SOCKET_ERROR is returned,
  1653.           and a specific error code is available in lpErrno.
  1654.  
  1655. Error Codes                   WSANOTINITIALISED   A
  1656.                               successful PSStartup() must
  1657.                               occur before using this SPI.
  1658.           
  1659.           WSAENETDOWN         The network subsystem has
  1660.                               failed.
  1661.           
  1662.           WSAEFAULT           The namelen argument is not
  1663.                               large enough.
  1664.           
  1665.           WSAEINPROGRESS      The function is invoked when a
  1666.                               callback is in progress.
  1667.           
  1668.           WSAENOTCONN         The socket is not connected.
  1669.           
  1670.           WSAENOTSOCK         The descriptor is not a
  1671.                               socket.
  1672.  
  1673. See Also  WSPBindWSPPSbind(), WSPsocket(),
  1674.           WSPGetSockNameWSPgetsockname().
  1675. 3.1.4 WSPGetSockNameWSPgetsockname()
  1676.  
  1677. Description    Get the local name for a socket.
  1678.  
  1679.           #include <ws2spi.h>
  1680.  
  1681.           int WSPAPI WSPGetSockNameWSPgetsockname ( SOCKET
  1682.           s, struct sockaddr FAR * name,
  1683.           int FAR * namelen, int FAR * lpErrno );
  1684.  
  1685.           
  1686.           s          A descriptor identifying a bound socket.
  1687.           
  1688.           name      Receives the address (name) of the
  1689.                     socket.
  1690.           
  1691.           namelen    The size of the name buffer.
  1692.           
  1693.           lpErrno   A pointer to the error code.
  1694.  
  1695. Remarks   WSPGetSockNameWSPPSgetsockname() retrieves the
  1696.           current name for the specified socket descriptor
  1697.           in name. It is used on a bound and/or connected
  1698.           socket specified by the s parameter. The local
  1699.           association is returned. This call is especially
  1700.           useful when a WSPConnect() call has been made
  1701.           without doing a WSPBindWSPbind() first; as this
  1702.           call provides the only means by which the local
  1703.           association which has been set by the service
  1704.           provider can be determinedyou can determine the
  1705.           local association which has been set by the
  1706.           system.
  1707.  
  1708.           On return, the namelen argument contains the
  1709.           actual size of the name returned in bytes.
  1710.           
  1711.           If a socket was bound to an unspecified address
  1712.           (e.g., ADDR_ANY), indicating that any of the
  1713.           host's addresses within the specified address
  1714.           family should be used for the socket,
  1715.           WSPGetSockNameWSPgetsockname() will not
  1716.           necessarily return information about the host
  1717.           address, unless the socket has been connected with
  1718.           WSPConnect() or WSPAccept. The Winsock DLL must
  1719.           not assume that the address will be specified
  1720.           unless the socket is connected. This is because
  1721.           for a multi-homed host the address that will be
  1722.           used for the socket is unknown unless the socket
  1723.           is connected.
  1724.  
  1725. Return Value   If no error occurs,
  1726.           WSPGetSockNameWSPgetsockname() returns 0.
  1727.           Otherwise, a value of SOCKET_ERROR is returned,
  1728.           and a specific error code is available in lpErrno.
  1729.  
  1730. Error Codes                   WSANOTINITIALISED   A
  1731.                               successful PSStartup() must
  1732.                               occur before using this SPI.
  1733.           
  1734.           WSAENETDOWN         The network subsystem has
  1735.                               failed.
  1736.           
  1737.           WSAEFAULT           The namelen argument is not
  1738.                               large enough, or the name or
  1739.                               namelen argument is not part
  1740.                               of the user address space.
  1741.           
  1742.           WSAEINPROGRESS      The function is invoked when a
  1743.                               callback is in progress.
  1744.           
  1745.           WSAENOTSOCK         The descriptor is not a
  1746.                               socket.
  1747.           
  1748.           WSAEINVAL           The socket has not been bound
  1749.                               to an address with
  1750.                               WSPBindWSPbind(), or ADDR_ANY
  1751.                               is specified in
  1752.                               WSPBindWSPbind() but
  1753.                               connection has not yet occurs.
  1754.  
  1755. See Also  WSPBindWSPPSbind(), WSPsocket(),
  1756.           WSPGetPeerNameWSPgetpeername().
  1757. 3.1.5 WSPGetSockOptWSPgetsockopt()
  1758.  
  1759. Description    Retrieve a socket option.
  1760.  
  1761.           #include <ws2spi.h>
  1762.  
  1763.           int WSPAPI WSPGetSockOptWSPgetsockopt ( SOCKET s,
  1764.           int level, int optname,
  1765.           char FAR * optval, int FAR * optlen, int FAR *
  1766.           lpErrno );
  1767.  
  1768.           
  1769.           s          A descriptor identifying a socket.
  1770.           
  1771.           level     The level at which the option is
  1772.                     defined; the only supported levels are
  1773.                     SOL_SOCKET and SOL_PROVIDER.
  1774.                     (SOL_PROVIDER is defined to be an alias
  1775.                     for IPPROTO_TCP for the sake of
  1776.                     compatibility with Windows Sockets
  1777.                     specification 1.1.)
  1778.           
  1779.           optname   The socket option for which the value is
  1780.                     to be retrieved.
  1781.           
  1782.           optval    A pointer to the buffer in which the
  1783.                     value for the requested option is to be
  1784.                     returned.
  1785.           
  1786.           optlen    A pointer to the size of the optval
  1787.                     buffer.
  1788.           
  1789.           lpErrno   A pointer to the error code.
  1790.  
  1791. Remarks   WSPGetSockOptWSPPSgetsockopt() retrieves the
  1792.           current value for a socket option associated with
  1793.           a socket of any type, in any state, and stores the
  1794.           result in optval. Options may exist at multiple
  1795.           protocol levels, but they are always present at
  1796.           the uppermost "socket'' level. Options affect
  1797.           socket operations, such as whether an operation
  1798.           blocks or not, the routing of packets, out-of-band
  1799.           data transfer, etc.
  1800.  
  1801.           The value associated with the selected option is
  1802.           returned in the buffer optval. The integer pointed
  1803.           to by optlen should originally contain the size of
  1804.           this buffer; on return, it will be set to the size
  1805.           of the value returned. For SO_LINGER, this will be
  1806.           the size of a struct linger; for most other
  1807.           options it will be the size of an integer.
  1808.           
  1809.           The Winsock DLL is responsible for allocating any
  1810.           memory space pointed to directly or indirectly by
  1811.           any of the parameters it specifiesd.
  1812.           
  1813.           If the option was never set with
  1814.           WSPSetSockOptWSPsetsockopt(), then
  1815.           WSPGetSockOptWSPgetsockopt() returns the default
  1816.           value for the option.
  1817.           
  1818. level = SOL_SOCKET                       
  1819. Value                            Type    Meaning
  1820. SO_ACCEPTCONN                    BOOL    Socket is
  1821.                                          WSPListenWSPlisten()ing.
  1822. SO_BROADCAST                     BOOL    Socket is configured for
  1823.                                          the transmission of
  1824.                                          broadcast messages.
  1825. SO_DEBUG                         BOOL    Debugging is enabled.
  1826. SO_DONTLINGER                    BOOL    If true, the SO_LINGER
  1827.                                          option is disabled.
  1828. SO_DONTROUTE                     BOOL    Routing is disabled.
  1829. SO_FLOWSPEC                      char    The flow spec of this
  1830.                                  FAR *   socket.
  1831. SO_GROUP_FLOWSPEC                char    The flow spec of the
  1832.                                  FAR *   socket group to which this
  1833.                                          socket belongs.
  1834. SO_GROUP_ID                      GROUP   The identifier of the
  1835.                                          group to which this socket
  1836.                                          belongs.
  1837. SO_GROUP_PRIORITY                int     The relative priority for
  1838.                                          sockets that are part of a
  1839.                                          socket group.
  1840. SO_KEEPALIVE                     BOOL    Keepalives are being sent.
  1841. SO_LINGER                        struct  Returns the current linger
  1842.                                  linger  options.
  1843. SO_MAX_MSGDG_SIZE                unsigne Maximum size of a message
  1844.                                  d int   for message-oriented
  1845.                                          socket types (e.g. DGRAM
  1846.                                          and DSTREAM). Has no
  1847.                                          meaning for stream-
  1848.                                          oriented sockets.
  1849. SO_OOBINLINE                     BOOL    Out-of-band data is being
  1850.                                          received in the normal
  1851.                                          data stream.
  1852. SO_PROTOCOL_INFO                 struct  Description of protocol
  1853.                                  PROTOCO info for protocol that is
  1854.                                  L_INFO  bound to this socket.
  1855. SO_RCVBUF                        int     Buffer size for receives
  1856. SO_REUSEADDR                     BOOL    The socket may be bound to
  1857.                                          an address which is
  1858.                                          already in use.
  1859. SO_SNDBUF                        int     Buffer size for sends
  1860. SO_TYPE                          int     The type of the socket
  1861.                                          (e.g. SOCK_STREAM).
  1862.                                          
  1863. level = SOL_PROVIDER                     
  1864.  (also aliased to IPPROTO_TCP)
  1865. PVD_CONFIG                       Service An "opaque" data structure
  1866.                                  Provide object from the service
  1867.                                  r       provider associated with
  1868.                                  Depende socket s. This object
  1869.                                  nt      stores the current
  1870.                                          configuration information
  1871.                                          of the service provider.
  1872.                                          The exact format of this
  1873.                                          data structure is service
  1874.                                          provider specific.
  1875. TCP_NODELAY                      BOOL    Disables the Nagle
  1876.                                          algorithm for send
  1877.                                          coalescing.
  1878.                
  1879.                BSD options not supported for
  1880.                WSPGetSockOptWSPgetsockopt() are:
  1881.                
  1882. Value                       Type     Meaning
  1883. SO_ERROR                    int      Get error status and clear
  1884. SO_RCVLOWAT                 int      Receive low water mark
  1885. SO_RCVTIMEO                 int      Receive timeout
  1886. SO_SNDLOWAT                 int      Send low water mark
  1887. SO_SNDTIMEO                 int      Send timeout
  1888. IP_OPTIONS                           Get options in IP header.
  1889. TCP_MAXSEG                  int      Get TCP maximum segment
  1890.                                      size.
  1891.  
  1892.           Calling WSPGetSockOptWSPgetsockopt() with an
  1893.           unsupported option will result in an error code of
  1894.           WSAENOPROTOOPT being returned in lpErrno.
  1895.           
  1896.      SO_DEBUG
  1897.           Winsock service providers are encouraged (but not
  1898.           required) to supply output debug information if
  1899.           the SO_DEBUG option is set by an application. The
  1900.           mechanism for generating the debug information and
  1901.           the form it takes are beyond the scope of this
  1902.           specification.
  1903.           
  1904.      SO_FLOWSPEC
  1905.           This is a get-only socket option which indicates
  1906.           the flow spec of the socket. The default flow spec
  1907.           defined in Sec. 2.8.3 will be returned before the
  1908.           application sets the flow spec for this socket.
  1909.           The WSAENOPROTOOPT error code is indicated for
  1910.           service providers which do not support the flow
  1911.           spec option. See WSPConnect() about how to set the
  1912.           flow spec.
  1913.           
  1914.      SO_GROUP_FLOWSPEC
  1915.           This is a get-only socket option which indicates
  1916.           the flow spec of the group this socket belongs to.
  1917.           The default flow spec defined in Sec. 2.8.3 will
  1918.           be returned before the application sets the flow
  1919.           spec for this socket group. The WSAENOPROTOOPT
  1920.           error code is indicated for service providers
  1921.           which do not support the group flow spec option.
  1922.           If this socket does not belong to an appropriate
  1923.           socket group, the Flen and Blen fields of the
  1924.           returned QOS struct are set to 0. See WSPConnect()
  1925.           about how to set the flow spec.
  1926.           
  1927.      SO_GROUP_ID
  1928.           This is a get-only socket option which indicates
  1929.           the identifier of the group this socket belongs
  1930.           to. If this socket is not a group socket, the
  1931.           value is NULL.
  1932.           
  1933.           The group option is provided as a way to
  1934.           facilitate the formation of multiplex
  1935.           relationships between two or more sockets (each
  1936.           with the group option set) that will share an
  1937.           underlying physical connection.  While such
  1938.           multiplexing is an assumed attribute of packet
  1939.           switched networks, the assumption does not
  1940.           necessarily hold true for circuit switched
  1941.           networks.  By setting this option, the application
  1942.           indicates a preference for eligible sockets to be
  1943.           multiplexed together.
  1944.           
  1945.      SO_GROUP_PRIORITY
  1946.           Group priority indicates the relative priority of
  1947.           the specified socket relative to other sockets
  1948.           within the socket group. Values are non-negative
  1949.           integers, with zero corresponding to the highest
  1950.           priority. Priority values represent a hint to the
  1951.           underlying service provider about how potentially
  1952.           scarce resources should be allocated. For example,
  1953.           whenever two or more sockets are both ready to
  1954.           transmit data, the highest priority socket (lowest
  1955.           value for SO_GROUP_PRIORITY) should be serviced
  1956.           first, with the remainder serviced in turn
  1957.           according to their relative priorities.
  1958.           
  1959.           The WSAENOPROTOOPT error code is indicated for non
  1960.           group sockets or for service providers which do
  1961.           not support group sockets.
  1962.           
  1963.      SO_KEEPALIVE
  1964.           An application may request that a TCP/IP service
  1965.           provider enable the use of "keep-alive" packets on
  1966.           TCP connections by turning on the SO_KEEPALIVE
  1967.           socket option. A Winsock provider need not support
  1968.           the use of keep-alives: if it does, the precise
  1969.           semantics are implementation-specific but should
  1970.           conform to section 4.2.3.6 of RFC 1122:
  1971.           Requirements for Internet Hosts -- Communication
  1972.           Layers. If a connection is dropped as the result
  1973.           of "keep-alives" the error code WSAENETRESET is
  1974.           returned to any calls in progress on the socket,
  1975.           and any subsequent calls will fail with
  1976.           WSAENOTCONN.
  1977.           
  1978.      SO_LINGER
  1979.           SO_LINGER controls the action taken when unsent
  1980.           data is queued on a socket and a
  1981.           WSPCloseSocketWSPclosesocket() is performed. See
  1982.           WSPCloseSocketWSPclosesocket() for a description
  1983.           of the way in which the SO_LINGER settings affect
  1984.           the semantics of WSPCloseSocketWSPclosesocket().
  1985.           The application gets the desired behavior by
  1986.           creating a struct linger (pointed to by the optval
  1987.           argument) with the following elements:
  1988.           
  1989.           struct linger {
  1990.                int  l_onoff;
  1991.                int  l_linger;
  1992.           }
  1993.           
  1994.           
  1995.           To enable SO_LINGER, the application should set
  1996.           l_onoff to a non-zero value, set l_linger to 0 or
  1997.           the desired timeout (in seconds), and call
  1998.           PSsetsockopt().  To enable SO_DONTLINGER (i.e.
  1999.           disable SO_LINGER) l_onoff should be set to zero
  2000.           and PSsetsockopt() should be called.
  2001.           
  2002.      SO_MAX_MSGDG_SIZE
  2003.           This is a get-only socket option which indicates
  2004.           the maximum size of a message for message-oriented
  2005.           socket types (e.g. DGRAM or DSTREAM) as
  2006.           implemented by a particular service provider. It
  2007.           has no meaning for byte stream oriented sockets
  2008.           
  2009.      SO_RESERVED_BW and SO_AVAILABLE_BW
  2010.           These options are used primarily with isochronous
  2011.           sockets, although both options have meaningful
  2012.           interpretations for non-isochronous sockets as
  2013.           well.  When dealing with isochronous sockets, the
  2014.           application may retrieve the value of
  2015.           SO_AVAILABLE_BW to determine the maximum amount of
  2016.           bandwidth that is available to be reserved.  It
  2017.           uses SO_RESERVED_BW to actually request bandwidth
  2018.           allocation or to determine the current bandwidth
  2019.           already allocated to the socket.  In both
  2020.           instances, bandwidth values are expressed in "bits
  2021.           per second (bps)".
  2022.           
  2023.           For non-isochronous sockets, the value of
  2024.           SO_AVAILABLE_BW is used to provide a hint as to
  2025.           the relative capacity of the underlying network.
  2026.           Applications may wish to know, for example,
  2027.           whether they are running over a 1200 baud serial
  2028.           line or a 155 Mbps ATM link. Since in many
  2029.           instances it is impossible for a non-isochronous
  2030.           service provider to supply a precise value for
  2031.           this option, applications must realize that the
  2032.           supplied value may represent nothing more than a
  2033.           reasonable approximation of the capacity of the
  2034.           underlying network.  Applications may likewise use
  2035.           the value of SO_RESERVED_BW to provide a hint to
  2036.           the service provider about the desired amount of
  2037.           bandwidth.
  2038.           
  2039.      SO_REUSEADDR
  2040.           By default, a socket may not be bound (see
  2041.           WSPBindWSPbind()) to a local address which is
  2042.           already in use. On occasions, however, it may be
  2043.           desirable to "re-use" an address in this way.
  2044.           Since every connection is uniquely identified by
  2045.           the combination of local and remote addresses,
  2046.           there is no problem with having two sockets bound
  2047.           to the same local address as long as the remote
  2048.           addresses are different. To inform the Winsock
  2049.           provider that a WSPBindWSPbind() on a socket
  2050.           should not be disallowed because the desired
  2051.           address is already in use by another socket, the
  2052.           application should set the SO_REUSEADDR socket
  2053.           option for the socket before issuing the
  2054.           WSPBindWSPbind(). Note that the option is
  2055.           interpreted only at the time of the
  2056.           WSPBindWSPbind(): it is therefore unnecessary (but
  2057.           harmless) to set the option on a socket which is
  2058.           not to be bound to an existing address, and
  2059.           setting or resetting the option after the
  2060.           WSPBindWSPbind() has no effect on this or any
  2061.           other socket.
  2062.           
  2063.      PVD_CALL_ID
  2064.           This is a get-only socket option which corresponds
  2065.           to an opaque Winsock call ID used for
  2066.           Winsock/Telephony Integration. See Appendix C for
  2067.           details. Winsock service providers which are not
  2068.           also TAPI service providers should return an
  2069.           WSAENOPROTOOPT error code when this option's value
  2070.           is requested.
  2071.           
  2072.      PVD_CONFIG
  2073.           This option retrieves an "opaque" data structure
  2074.           object from the service provider associated with
  2075.           socket s. This object stores the current
  2076.           configuration information of the service provider.
  2077.           The exact format of this data structure is service
  2078.           provider specific.
  2079.           
  2080.      TCP_NODELAY
  2081.           The TCP_NODELAY option disables the Nagle
  2082.           algorithm. The Nagle algorithm is used to reduce
  2083.           the number of small packets sent by a host by
  2084.           buffering unacknowledged send data until a full-
  2085.           size packet can be sent. However, for some
  2086.           applications this algorithm can impede
  2087.           performance, and TCP_NODELAY may be used to turn
  2088.           it off. Application writers should not set
  2089.           TCP_NODELAY unless the impact of doing so is well-
  2090.           understood and desired, since setting TCP_NODELAY
  2091.           can have a significant negative impact of network
  2092.           performance.
  2093.           
  2094.      TAPI_DEVICE_ID
  2095.           This is a get-only socket option which corresponds
  2096.           to a line device ID for Windows Telephony API
  2097.           (TAPI). See Appendix C for details. Winsock
  2098.           service providers which are not also TAPI service
  2099.           providers should return an WSAENOPROTOOPT error
  2100.           code when this option's value is requested.
  2101.  
  2102. Return Value   If no error occurs,
  2103.           WSPGetSockOptWSPgetsockopt() returns 0. Otherwise,
  2104.           a value of SOCKET_ERROR is returned, and a
  2105.           specific error code is available in lpErrno.
  2106.  
  2107. Error Codes                   WSANOTINITIALISED   A
  2108.                               successful PSStartup() must
  2109.                               occur before using this SPI.
  2110.           
  2111.           WSAENETDOWN         The network subsystem has
  2112.                               failed.
  2113.           
  2114.           WSAEFAULT           The optlen argument was
  2115.                               invalid.
  2116.           
  2117.           WSAEINVAL           No value available for optname
  2118.                               at the moment.
  2119.           
  2120.           WSAEINPROGRESS      The function is invoked when a
  2121.                               callback is in progress.
  2122.           
  2123.           WSAENOPROTOOPT      The option is unknown or
  2124.                               unsupported by the indicated
  2125.                               protocol family.
  2126.           
  2127.           WSAENOTSOCK         The descriptor is not a
  2128.                               socket.
  2129.  
  2130. See Also  WSPSetSockOptWSPPSsetsockopt(),WSPsocket().
  2131. 3.1.6 WSPIoctlSocketWSPioctlsocket()
  2132.  
  2133. Description    Control the mode of a socket.
  2134.  
  2135.           #include <ws2spi.h>
  2136.  
  2137.           int WSPAPI WSPIoctlSocketWSPioctlsocket ( SOCKET
  2138.           s, long cmd, u_long FAR * argp,
  2139.           int FAR * lpErrno );
  2140.  
  2141.           
  2142.           s          A descriptor identifying a socket.
  2143.           
  2144.           cmd       The command to perform on the socket s.
  2145.           
  2146.           argp      A pointer to a parameter for cmd.
  2147.           
  2148.           lpErrno   A pointer to the error code.
  2149.  
  2150. Remarks   This routine may be used on any socket in any
  2151.           state. It is used to get or retrieve operating
  2152.           parameters associated with the socket, independent
  2153.           of the protocol and communications subsystem. The
  2154.           following commands are supported:
  2155.  
  2156.           Command   Semantics
  2157.           
  2158.           FIONBIO   Enable or disable non-blocking mode on
  2159.                     the socket s.  argp points at an
  2160.                     unsigned long, which is non-zero if non-
  2161.                     blocking mode is to be enabled and zero
  2162.                     if it is to be disabled.  When a socket
  2163.                     is created, it operates in blocking mode
  2164.                     (i.e. non-blocking mode is disabled).
  2165.                     This is consistent with BSD sockets.
  2166.           
  2167.                     The PSCallbackSelect() routine
  2168.                     automatically sets a socket to
  2169.                     nonblocking mode.  If PSCallbackSelect()
  2170.                     has been issued on a socket, then any
  2171.                     attempt to use PSioctlsocket() to set
  2172.                     the socket back to blocking mode will
  2173.                     fail with WSAEINVAL.  To set the socket
  2174.                     back to blocking mode, an application
  2175.                     must first disable PSCallbackSelect() by
  2176.                     calling PSCallbackSelect() with the
  2177.                     lEvent parameter equal to 0.
  2178.           
  2179.           FIONREAD  Determine the amount of data which can
  2180.                     be read atomically from socket s. argp
  2181.                     points at an unsigned long in which
  2182.                     WSPIoctlSocketWSPioctlsocket() stores
  2183.                     the result. If s is stream-oriented
  2184.                     (e.g., type SOCK_STREAM), FIONREAD
  2185.                     returns the total amount of data which
  2186.                     may be read in a single
  2187.                     WSPRecvWSPrecv(); this is normally the
  2188.                     same as the total amount of data queued
  2189.                     on the socket. If s is message-oriented
  2190.                     (e.g., type SOCK_DGRAM), FIONREAD
  2191.                     returns the size of the first datagram
  2192.                     (message) queued on the socket.
  2193.           
  2194.           SIOCATMARK     Determine whether or not all out-of-
  2195.                     band data has been read. This applies
  2196.                     only to a socket of stream style (e.g.,
  2197.                     type SOCK_STREAM) which has been
  2198.                     configured for in-line reception of any
  2199.                     out-of-band data (SO_OOBINLINE). If no
  2200.                     out-of-band data is waiting to be read,
  2201.                     the operation returns TRUE. Otherwise it
  2202.                     returns FALSE, and the next
  2203.                     WSPRecvWSPrecv() or
  2204.                     WSPRecvFromWSPrecvfrom() performed on
  2205.                     the socket will retrieve some or all of
  2206.                     the data preceding the "mark"; the
  2207.                     application should use the SIOCATMARK
  2208.                     operation to determine whether any
  2209.                     remains. If there is any normal data
  2210.                     preceding the "urgent" (out of band)
  2211.                     data, it will be received in order.
  2212.                     (Note that a WSPRecvWSPrecv() or
  2213.                     WSPRecvFromWSPrecvfrom() will never mix
  2214.                     out-of-band and normal data in the same
  2215.                     call.) argp points at a BOOL in which
  2216.                     WSPIoctlSocketWSPioctlsocket() stores
  2217.                     the result.
  2218.  
  2219. Compatibility  This function is a subset of ioctl() as used
  2220.           in Berkeley sockets. In particular, there is no
  2221.           command which is equivalent to FIOASYNC, while
  2222.           SIOCATMARK is the only socket-level command which
  2223.           is supported.
  2224. {where should we break the news about not allowing any new
  2225.           ioctls to be introduced? }
  2226. {Not here. This is more of a charter/requirements issue for
  2227.           the API extension group.}
  2228.  
  2229. Return Value   Upon successful completion, the
  2230.           WSPIoctlSocketWSPioctlsocket() returns 0.
  2231.           Otherwise, a value of SOCKET_ERROR is returned,
  2232.           and a specific error code is available in lpErrno.
  2233.  
  2234. Error Codes                   WSANOTINITIALISED   A
  2235.                               successful PSStartup() must
  2236.                               occur before using this SPI.
  2237.           
  2238.           WSAENETDOWN         The network subsystem has
  2239.                               failed.
  2240.           
  2241.           WSAEINVAL           cmd is not a valid command, or
  2242.                               argp is not an acceptable
  2243.                               parameter for cmd, or the
  2244.                               command is not applicable to
  2245.                               the type of socket supplied
  2246.           
  2247.           WSAEINPROGRESS      The function is invoked when a
  2248.                               callback is in progress.
  2249.           
  2250.           WSAENOTSOCK         The descriptor s is not a
  2251.                               socket.
  2252.           
  2253.  
  2254. See Also  WSPPSsocket(), WSPSetSockOptWSPsetsockopt(),
  2255.           WSPGetSockOptWSPgetsockopt().
  2256. 3.1.7 WSPListenWSPlisten()
  2257.  
  2258. Description    Establish a socket to listen for incoming
  2259.           connection.
  2260.  
  2261.           #include <ws2spi.h>
  2262.  
  2263.           int WSPAPI WSPListenWSPlisten ( SOCKET s, int
  2264.           backlog, int FAR * lpErrno );
  2265.           
  2266.           s          A descriptor identifying a bound,
  2267.                     unconnected socket.
  2268.           
  2269.           backlog   The maximum length to which the queue of
  2270.                     pending connections may grow.
  2271.           
  2272.           lpErrno   A pointer to the error code.
  2273.  
  2274. Remarks   To accept connections, a socket is first created
  2275.           with WSPsocket(), a backlog for incoming
  2276.           connections is specified with
  2277.           WSPListenWSPlisten(), and then the connections are
  2278.           accepted with WSPAccept. WSPListenWSPlisten()
  2279.           applies only to sockets that are connection-
  2280.           oriented (, e.g., those of type SOCK_STREAM). The
  2281.           socket s is put into "passive'' mode where
  2282.           incoming connections are acknowledged and queued
  2283.           pending acceptance by the process.
  2284.  
  2285.           This function is typically used by servers that
  2286.           could have more than one connection request at a
  2287.           time: if a connection request arrives with the
  2288.           queue full, the client will receive an error with
  2289.           an indication of WSAECONNREFUSED.
  2290.  
  2291.           PSlisten() attempts to continue to function
  2292.           rationally when there are no available
  2293.           descriptors.  It will accept connections until the
  2294.           queue is emptied.  If descriptors become
  2295.           available, a later call to PSlisten() or
  2296.           PSaccept() will re-fill the queue to the current
  2297.           or most recent "backlog'', if possible, and resume
  2298.           listening for incoming connections.
  2299.           
  2300. Compatibility  backlog is currently limited (silently) to
  2301.           SOMAXCONN, which is defined to be 5 in the header
  2302.           file. As in 4.3BSD, illegal values (less than 1 or
  2303.           greater than 5) are replaced by the nearest legal
  2304.           value.
  2305.           {Why do we still enforce this? NT limits the
  2306.           backlog to 100, not 5, because BIG servers (like
  2307.           ftp.microsoft.com) often receive periodic floods
  2308.           of connection requests, easily overrunning a
  2309.           backlog of 5 connections.}
  2310.  
  2311. Return Value   If no error occurs, WSPListenWSPlisten()
  2312.           returns 0. Otherwise, a value of SOCKET_ERROR is
  2313.           returned, and a specific error code is available
  2314.           in lpErrno.
  2315.  
  2316. Error Codes                   WSANOTINITIALISED   A
  2317.                               successful PSStartup() must
  2318.                               occur before using this SPI.
  2319.           
  2320.           WSAENETDOWN         The network subsystem has
  2321.                               failed.
  2322.           
  2323.           WSAEADDRINUSE       An attempt has been made to
  2324.                               WSPListenWSPlisten() on an
  2325.                               address in use.
  2326.           
  2327.           WSAEINPROGRESS      The function is invoked when a
  2328.                               callback is in progress.
  2329.           
  2330.           WSAEINVAL           The socket has not been bound
  2331.                               with WSPBindWSPbind().
  2332.           
  2333.           WSAEISCONN          The socket is already
  2334.                               connected.
  2335.           
  2336.           WSAEMFILE           No more socket descriptors are
  2337.                               available.
  2338.           
  2339.           WSAENOBUFS          No buffer space is available.
  2340.           
  2341.           WSAENOTSOCK         The descriptor is not a
  2342.                               socket.
  2343.           
  2344.           WSAEOPNOTSUPP       The referenced socket is not
  2345.                               of a type that supports the
  2346.                               WSPListenWSPlisten()
  2347.                               operation.
  2348.  
  2349. See Also  WSPAccept, WSPConnect(), WSPsocket().
  2350. 3.1.8 WSPSelectWSPselect32()
  2351.  
  2352. Description    Determine the status of one or more sockets.
  2353.  
  2354.           #include <ws2spi.h>
  2355.  
  2356.           int WSPAPI WSPSelectWSPselect32 ( int nfds, fd_set
  2357.           FAR * readfds, fd_set FAR * writefds,  fd_set FAR
  2358.           * exceptfds, const struct timeval FAR * timeout,
  2359.           int FAR * lpErrno );
  2360.  
  2361.           
  2362.           nfds      This argument is ignored and included
  2363.                     only for the sake of compatibility.
  2364.           
  2365.           readfds   An optional pointer to a set of sockets
  2366.                     to be checked for readability.
  2367.           
  2368.           writefds  An optional pointer to a set of sockets
  2369.                     to be checked for writability
  2370.           
  2371.           exceptfds An optional pointer to a set of sockets
  2372.                     to be checked for errors.
  2373.           
  2374.           timeout   The maximum time for PSselect() to wait,
  2375.                     or NULL for blocking operation.This
  2376.                     value istTThis value should be ignored.
  2377.                     (The Winsock DLL will always supply a
  2378.                     value of zero for the sake of
  2379.                     compatability.)The maximum time for
  2380.                     WSPSelect() to wait, or NULL for a
  2381.                     blocking operation. Note that the 16-bit
  2382.                     Winsock DLL will always pass in a
  2383.                     timeout of zero to perform a non-
  2384.                     blocking poll on the socket set(s). The
  2385.                     32-bit Winsock DLL may pass in any
  2386.                     timeout value.
  2387.           
  2388.           lpErrno   A pointer to the error code.
  2389.  
  2390. Remarks   This function is only applicable to the 32 bit
  2391.           SPI. The 16 bit Winsock2.DLL uses the
  2392.           WSPCallbackSelect() function to implement the API
  2393.           version of select() since blocking may be
  2394.           requested. WSPSelect32() is used to determine the
  2395.           status of one or more sockets. For each socket,
  2396.           the caller may request information on read, write
  2397.           or error status. The set of sockets for which a
  2398.           given status is requested is indicated by an
  2399.           fd_set structure. All entries in an fd_set
  2400.           correspond to sockets created by the service
  2401.           provider. Upon return, the structure is updated to
  2402.           reflect the subset of these sockets which meet the
  2403.           specified condition, and WSPSelectWSPselect32()
  2404.           returns the total number of sockets meeting the
  2405.           conditions. A set of macros is provided for
  2406.           manipulating an fd_set. These macros are
  2407.           compatible with those used in the Berkeley
  2408.           software, but the underlying representation is
  2409.           completely different.
  2410.           
  2411.           The parameter readfds identifies those sockets
  2412.           which are to be checked for readability. If the
  2413.           socket is currently WSPListenWSPlisten()ing, it
  2414.           will be marked as readable if an incoming
  2415.           connection request has been received, so that an
  2416.           WSPAccept is guaranteed to complete immediately.
  2417.           For other sockets, readability means that queued
  2418.           data is available for reading or, for connection-
  2419.           oriented sockets, that the virtual circuit
  2420.           corresponding to the socket has been closed, so
  2421.           that a WSPRecvWSPrecv() or
  2422.           WSPRecvFromWSPrecvfrom() is guaranteed to complete
  2423.           immediately. If the virtual circuit was closed
  2424.           gracefully, then a WSPRecvWSPrecv() will return
  2425.           immediately with 0 bytes read; if the virtual
  2426.           circuit was reset, then a WSPRecvWSPrecv() will
  2427.           complete immediately with the error code
  2428.           WSAECONNRESET. The presence of out-of-band data
  2429.           will be checked if the socket option SO_OOBINLINE
  2430.           has been enabled (see
  2431.           WSPSetSockOptWSPsetsockopt()).
  2432.           
  2433.           The parameter writefds identifies those sockets
  2434.           which are to be checked for writability. If a
  2435.           socket is WSPConnect()ing, writability means that
  2436.           the connection establishment successfully
  2437.           completed. If the socket is not in the process of
  2438.           WSPConnect()ing, writability means that a
  2439.           WSPSendWSPsend() or WSPSendToWSPsendto() or
  2440.           WSAGetBuffer() will complete immediately. [It is
  2441.           not specified how long this guarantee can be
  2442.           assumed to be valid, particularly in a
  2443.           multithreaded environment.]
  2444.           
  2445.           The parameter exceptfds identifies those sockets
  2446.           which are to be checked for the presence of out-of-
  2447.           band data or any exceptional error conditions.
  2448.           Note that out-of-band data will only be reported
  2449.           in this way if the option SO_OOBINLINE is FALSE.
  2450.           For a connection-oriented socket, the breaking of
  2451.           the connection by the peer or due to KEEPALIVE
  2452.           failure will be indicated as an exception. This
  2453.           specification does not define which other errors
  2454.           will be included. If a socket is WSPConnect()ing,
  2455.           failure of the connect attempt is indicated in
  2456.           exceptfds.
  2457.           
  2458.           Any of readfds, writefds, or exceptfds may be
  2459.           given as NULL if no descriptors are of interest.
  2460.           
  2461.           Four macros are defined in the header file
  2462.           ws2spi.h for manipulating the descriptor sets. The
  2463.           variable FD_SETSIZE determines the maximum number
  2464.           of descriptors in a set. (The default value of
  2465.           FD_SETSIZE is 64, which may be modified by
  2466.           #defining FD_SETSIZE to another value before
  2467.           #including ws2spi.h.) Internally, an fd_set is
  2468.           represented as an array of SOCKETs; the last valid
  2469.           entry is followed by an element set to
  2470.           INVALID_SOCKET. The macros are:
  2471.           
  2472.           FD_CLR(s, *set)          Removes the descriptor s
  2473.                     from set.
  2474.           
  2475.           FD_ISSET(s, *set)   Nonzero if s is a member of
  2476.                     the set, zero otherwise.
  2477.           
  2478.           FD_SET(s, *set)          Adds descriptor s to set.
  2479.           
  2480.           FD_ZERO(*set)       Initializes the set to the
  2481.                     NULL set.
  2482.           
  2483.           The parameter timeout controls how long the
  2484.           PSselect() may take to complete.  If timeout is a
  2485.           null pointer, PSselect() will block indefinitely
  2486.           until at least one descriptor meets the specified
  2487.           criteria.  Otherwise, timeout points to a struct
  2488.           timeval which specifies the maximum time that
  2489.           PSselect() should wait before returning.  If the
  2490.           timeval is initialized to {0, 0}, PSselect() will
  2491.           return immediately; this is used to "poll" the
  2492.           state of the selected sockets.  If this is the
  2493.           case, then the PSselect() call is considered
  2494.           nonblocking and the standard assumptions for
  2495.           nonblocking calls apply.  For example, the
  2496.           blocking hook must not be called, and the PII
  2497.           implementation must not yield.
  2498.  
  2499. Return Value   WSPPSSelectselect32() returns the total
  2500.           number of descriptors which are ready and
  2501.           contained in the fd_set structures, 0 if the time
  2502.           limit expired, or SOCKET_ERROR if an error
  2503.           occurred. If the return value is SOCKET_ERROR, a
  2504.           specific error code is available in lpErrno.
  2505.  
  2506. Comments  WSPPSSelect 32() has no effect on the
  2507.           persistencepersistance of socket events registered
  2508.           with WSPEventSelect().
  2509.  
  2510. Error Codes                   WSANOTINITIALISED   A
  2511.                               successful PSStartup() must
  2512.                               occur before using this API.
  2513.           
  2514.           WSAEFAULT           The Winsock service provider
  2515.                               was unable to allocated needed
  2516.                               resources for its internal
  2517.                               operations, or the readfds,
  2518.                               writefds, or exceptfds
  2519.                               parameters are not part of the
  2520.                               user address space.
  2521.           
  2522.           WSAENETDOWN         The network subsystem has
  2523.                               failed.
  2524.           
  2525.           WSAEINVAL           The timeout value is not
  2526.                               valid.
  2527.           
  2528.           WSAEINTR            The (blocking) call was
  2529.                               canceled via
  2530.                               WSACancelBlockingCall().
  2531.           
  2532.           WSAEINPROGRESS      The function is invoked when a
  2533.                               callback is in progress.
  2534.           
  2535.           WSAENOTSOCK         One of the descriptor sets
  2536.                               contains an entry which is not
  2537.                               a socket.
  2538.  
  2539. See Also  WSPAccept(), WSPConnect(), WSPRecvWSPrecv(),
  2540.           WSPRecvFromWSPrecvfrom(), WSPSendWSPsend(),
  2541.           WSPSendToWSPsendto(), WSPEventSelect()
  2542. 3.1.9 WSPSetSockOptWSPsetsockopt()
  2543.  
  2544. Description    Set a socket option.
  2545.  
  2546.           #include <ws2spi.h>
  2547.  
  2548.           int WSPAPI WSPSetSockOptWSPsetsockopt ( SOCKET s,
  2549.           int level, int optname,
  2550.           const char FAR * optval, int optlen, int FAR *
  2551.           lpErrno );
  2552.  
  2553.           
  2554.           s          A descriptor identifying a socket.
  2555.           
  2556.           level     The level at which the option is
  2557.                     defined; the only supported levels are
  2558.                     SOL_SOCKET and SOL_PROVIDER.
  2559.                     (SOL_PROVIDER is defined to be an alias
  2560.                     for IPPROTO_TCP for the sake of
  2561.                     compatibility with Windows Sockets
  2562.                     specification 1.1.)
  2563.           
  2564.           optname   The socket option for which the value is
  2565.                     to be set.
  2566.           
  2567.           optval    A pointer to the buffer in which the
  2568.                     value for the requested option is
  2569.                     supplied.
  2570.           
  2571.           optlen    The size of the optval buffer.
  2572.           
  2573.           lpErrno   A pointer to the error code.
  2574.  
  2575. Remarks   WSPSetSockOptWSPPSsetsockopt() sets the current
  2576.           value for a socket option associated with a socket
  2577.           of any type, in any state. Although options may
  2578.           exist at multiple protocol levels, they are always
  2579.           present at the uppermost "socket'' level. Options
  2580.           affect socket operations, such as whether
  2581.           expedited data is received in the normal data
  2582.           stream, whether broadcast messages may be sent on
  2583.           the socket, etc.
  2584.  
  2585.           There are two types of socket options: Boolean
  2586.           options that enable or disable a feature or
  2587.           behavior, and options which require an integer
  2588.           value or structure. To enable a Boolean option,
  2589.           optval points to a nonzero integer. To disable the
  2590.           option optval points to an integer equal to zero.
  2591.           optlen should be equal to sizeof(int) for Boolean
  2592.           options. For other options, optval points to the
  2593.           an integer or structure that contains the desired
  2594.           value for the option, and optlen is the length of
  2595.           the integer or structure.
  2596.           
  2597.           
  2598.  level = SOL_SOCKET                      
  2599.  Value                          Type     Meaning
  2600.  SO_BROADCAST                   BOOL     Allow transmission of
  2601.                                          broadcast messages on the
  2602.                                          socket.
  2603.  SO_DEBUG                       BOOL     Record debugging
  2604.                                          information.
  2605.  SO_DONTLINGER                  BOOL     Don't block close waiting
  2606.                                          for unsent data to be
  2607.                                          sent. Setting this option
  2608.                                          is equivalent to setting
  2609.                                          SO_LINGER with l_onoff set
  2610.                                          to zero.
  2611.  SO_DONTROUTE                   BOOL     Don't route: send directly
  2612.                                          to interface.
  2613.  SO_GROUP_PRIORITY              int      Specify the relative
  2614.                                          priority to be established
  2615.                                          for sockets that are part
  2616.                                          of a socket group.
  2617.  SO_KEEPALIVE                   BOOL     Send keepalives
  2618.  SO_LINGER                      struct   Linger on close if unsent
  2619.                                 linger   data is present
  2620.  SO_OOBINLINE                   BOOL     Receive out-of-band data
  2621.                                          in the normal data stream.
  2622.  SO_RCVBUF                      int      Specify buffer size for
  2623.                                          receives
  2624.  SO_REUSEADDR                   BOOL     Allow the socket to be
  2625.                                          bound to an address which
  2626.                                          is already in use. (See
  2627.                                          bind().)
  2628.  SO_SNDBUF                      int      Specify buffer size for
  2629.                                          sends.
  2630.                                          
  2631.  level = SOL_PROVIDER                    
  2632.  (aliased to IPPROTO_TCP)
  2633.  PVD_CONFIG                     Service  This object stores the
  2634.                                 Provide  configuration information
  2635.                                 r        for the service provider
  2636.                                 Depende  associated with socket s.
  2637.                                 nt       The exact format of this
  2638.                                          data structure is service
  2639.                                          provider specific.
  2640.  TCP_NODELAY                    BOOL     Disables the Nagle
  2641.                                          algorithm for send
  2642.                                          coalescing.
  2643.                
  2644.                BSD options not supported for
  2645.                WSPSetSockOptWSPsetsockopt() are:
  2646.                
  2647. Value                       Type     Meaning
  2648. SO_ACCEPTCONN               BOOL     Socket is listening
  2649. SO_ERROR                    int      Get error status and clear
  2650. SO_RCVLOWAT                 int      Receive low water mark
  2651. SO_RCVTIMEO                 int      Receive timeout
  2652. SO_SNDLOWAT                 int      Send low water mark
  2653. SO_SNDTIMEO                 int      Send timeout
  2654. SO_TYPE                     int      Type of the socket
  2655. IP_OPTIONS                           Set options field in IP
  2656.                                      header.
  2657.           
  2658.      SO_DEBUG
  2659.           Winsock service providers are encouraged (but not
  2660.           required) to supply output debug information if
  2661.           the SO_DEBUG option is set by an application. The
  2662.           mechanism for generating the debug information and
  2663.           the form it takes are beyond the scope of this
  2664.           specification.
  2665.           
  2666.      SO_GROUP_PRIORITY
  2667.           Group priority indicates the relative priority of
  2668.           the specified socket relative to other sockets
  2669.           within the socket group. Values are non-negative
  2670.           integers, with zero corresponding to the highest
  2671.           priority. Priority values represent a hint to the
  2672.           underlying service provider about how potentially
  2673.           scarce resources should be allocated. For example,
  2674.           whenever two or more sockets are both ready to
  2675.           transmit data, the highest priority socket (lowest
  2676.           value for SO_GROUP_PRIORITY) should be serviced
  2677.           first, with the remainder serviced in turn
  2678.           according to their relative priorities.
  2679.           
  2680.           
  2681.           
  2682.           Eligibility for grouping sockets together is based
  2683.           on the destination address of sockets marked with
  2684.           the group option.  Sockets which share destination
  2685.           addresses that are identical except for the last
  2686.           component of the address (e.g. the port number in
  2687.           the IP address family) are eligible for group
  2688.           multiplexing.  The manner in which multiplexing is
  2689.           implemented is left up to the service provider.The
  2690.           WSAENOPROTOOPT error is indicated for non group
  2691.           sockets or for service providers which do not
  2692.           support group sockets.
  2693.           
  2694.      SO_KEEPALIVE
  2695.           An application may request that a TCP/IP provider
  2696.           enable the use of "keep-alive" packets on TCP
  2697.           connections by turning on the SO_KEEPALIVE socket
  2698.           option. A Winsock provider need not support the
  2699.           use of keep-alives: if it does, the precise
  2700.           semantics are implementation-specific but should
  2701.           conform to section 4.2.3.6 of RFC 1122:
  2702.           Requirements for Internet Hosts -- Communication
  2703.           Layers. If a connection is dropped as the result
  2704.           of "keep-alives" the error code WSAENETRESET is
  2705.           returned to any calls in progress on the socket,
  2706.           and any subsequent calls will fail with
  2707.           WSAENOTCONN.
  2708.           
  2709.      SO_LINGER
  2710.           SO_LINGER controls the action taken when unsent
  2711.           data is queued on a socket and a
  2712.           WSPCloseSocketWSPclosesocket() is performed. See
  2713.           WSPCloseSocketWSPclosesocket() for a description
  2714.           of the way in which the SO_LINGER settings affect
  2715.           the semantics of WSPCloseSocketWSPclosesocket().
  2716.           The application sets the desired behavior by
  2717.           creating a struct linger (pointed to by the optval
  2718.           argument) with the following elements:
  2719.           
  2720.           struct linger {
  2721.                int  l_onoff;
  2722.                int  l_linger;
  2723.           }
  2724.           
  2725.           
  2726.           To enable SO_LINGER, the application should set
  2727.           l_onoff to a non-zero value, set l_linger to 0 or
  2728.           the desired timeout (in seconds), and call
  2729.           WSPSetSockOptWSPsetsockopt(). To enable
  2730.           SO_DONTLINGER (i.e. disable SO_LINGER) l_onoff
  2731.           should be set to zero and
  2732.           WSPSetSockOptWSPsetsockopt() should be called.
  2733.           
  2734.      SO_RESERVED_BW and SO_AVAILABLE_BW
  2735.           These options are used primarily with isochronous
  2736.           sockets, although both options have meaningful
  2737.           interpretations for non-isochronous sockets as
  2738.           well.  When dealing with isochronous sockets, the
  2739.           application may retrieve the value of
  2740.           SO_AVAILABLE_BW to determine the maximum amount of
  2741.           bandwidth that is available to be reserved.  It
  2742.           uses SO_RESERVED_BW to actually request bandwidth
  2743.           allocation or to determine the current bandwidth
  2744.           already allocated to the socket.  In both
  2745.           instances, bandwidth values are expressed in "bits
  2746.           per second (bps)".
  2747.           
  2748.           For non-isochronous sockets, the value of
  2749.           SO_AVAILABLE_BW is used to provide a hint as to
  2750.           the relative capacity of the underlying network.
  2751.           Applications may wish to know, for example,
  2752.           whether they are running over a 1200 baud serial
  2753.           line or a 155 Mbps ATM link. Since in many
  2754.           instances it is impossible for a non-isochronous
  2755.           service provider to supply a precise value for
  2756.           this option, applications must realize that the
  2757.           supplied value may represent nothing more than a
  2758.           reasonable approximation of the capacity of the
  2759.           underlying network.  Applications may likewise use
  2760.           the value of SO_RESERVED_BW to provide a hint to
  2761.           the service provider about the desired amount of
  2762.           bandwidth.
  2763.           
  2764.      SO_REUSEADDR
  2765.           By default, a socket may not be bound (see
  2766.           WSPBindWSPbind()) to a local address which is
  2767.           already in use. On occasions, however, it may be
  2768.           desirable to "re-use" an address in this way.
  2769.           Since every connection is uniquely identified by
  2770.           the combination of local and remote addresses,
  2771.           there is no problem with having two sockets bound
  2772.           to the same local address as long as the remote
  2773.           addresses are different. To inform the Winsock
  2774.           provider that a WSPBindWSPbind() on a socket
  2775.           should not be disallowed because the desired
  2776.           address is already in use by another socket, the
  2777.           application should set the SO_REUSEADDR socket
  2778.           option for the socket before issuing the
  2779.           WSPBindWSPbind(). Note that the option is
  2780.           interpreted only at the time of the
  2781.           WSPBindWSPbind(): it is therefore unnecessary (but
  2782.           harmless) to set the option on a socket which is
  2783.           not to be bound to an existing address, and
  2784.           setting or resetting the option after the
  2785.           WSPBindWSPbind() has no effect on this or any
  2786.           other socket.
  2787.           
  2788.      PVD_CONFIG
  2789.           This option specifies an object previously
  2790.           obtained using getsockopt().  This object stores
  2791.           the configuration information for the service
  2792.           provider associated with socket s. The exact
  2793.           format of this data structure is service provider
  2794.           specific.
  2795.           
  2796.      TCP_NODELAY
  2797.           The TCP_NODELAY option is specific to TCP/IP
  2798.           service providers. It is used to disable the Nagle
  2799.           algorithm. The Nagle algorithm is used to reduce
  2800.           the number of small packets sent by a host by
  2801.           buffering unacknowledged send data until a full-
  2802.           size packet can be sent. However, for some
  2803.           applications this algorithm can impede
  2804.           performance, and TCP_NODELAY may be used to turn
  2805.           it off. Application writers should not set
  2806.           TCP_NODELAY unless the impact of doing so is well-
  2807.           understood and desired, since setting TCP_NODELAY
  2808.           can have a significant negative impact of network
  2809.           performance.
  2810.           
  2811.  
  2812. Return Value   If no error occurs,
  2813.           WSPSetSockOptWSPsetsockopt() returns 0. Otherwise,
  2814.           a value of SOCKET_ERROR is returned, and a
  2815.           specific error code is available in lpErrno.
  2816.  
  2817. Error Codes                   WSANOTINITIALISED   A
  2818.                               successful PSStartup() must
  2819.                               occur before using this SPI.
  2820.           
  2821.           WSAENETDOWN         The network subsystem has
  2822.                               failed.
  2823.           
  2824.           WSAEFAULT           optval is not in a valid part
  2825.                               of the process address space.
  2826.           
  2827.           WSAEINPROGRESS      The function is invoked when a
  2828.                               callback is in progress.
  2829.           
  2830.           WSAEINVAL           level is not valid, or the
  2831.                               information in optval is not
  2832.                               valid.
  2833.           
  2834.           WSAENETRESET        Connection has timed out when
  2835.                               SO_KEEPALIVE is set.
  2836.           
  2837.           WSAENOPROTOOPT      The option is unknown or
  2838.                               unsupported for the specified
  2839.                               provider.
  2840.           
  2841.           WSAENOTCONN         Connection has been reset when
  2842.                               SO_KEEPALIVE is set.
  2843.           
  2844.           WSAENOTSOCK         The descriptor is not a
  2845.                               socket.
  2846.  
  2847. See Also  WSPBindWSPPSbind(), WSPGetSockOptWSPgetsockopt(),
  2848.           WSPIoctlSocketWSPioctlsocket(), WSPsocket(),
  2849.           WSPEventSelect().
  2850. 3.1.10 WSPShutdownWSPshutdown()
  2851.  
  2852. Description    Disable sends and/or receives on a socket.
  2853.  
  2854.           #include <ws2spi.h>
  2855.  
  2856.           int WSPAPI WSPShutdownWSPshutdown ( SOCKET s, int
  2857.           how, int FAR * lpErrno );
  2858.  
  2859.           
  2860.           s          A descriptor identifying a socket.
  2861.           
  2862.           how       A flag that describes what types of
  2863.                     operation will no longer be allowed.
  2864.           
  2865.           lpErrno   A pointer to the error code.
  2866.  
  2867. Remarks   WSPShutdownWSPPSshutdown() is used on all types of
  2868.           sockets to disable reception, transmission, or
  2869.           both.
  2870.  
  2871.           If how is SD_RECEIVE, subsequent receives on the
  2872.           socket will be disallowed. This has no effect on
  2873.           the lower protocol layers. For TCP, the TCP window
  2874.           is not changed and incoming data will be accepted
  2875.           (but not acknowledged) until the window is
  2876.           exhausted. For UDP, incoming datagrams are
  2877.           accepted and queued. In no case will an ICMP error
  2878.           packet be generated.
  2879.           
  2880.           If how is SD_SEND, subsequent sends on the socket
  2881.           are disallowed. For TCP sockets, a FIN will be
  2882.           sent.
  2883.           
  2884.           Setting how to SD_BOTH disables both sends and
  2885.           receives as described above.
  2886.  
  2887.           Note that WSPShutdownWSPshutdown() does not close
  2888.           the socket, and resources attached to the socket
  2889.           will not be freed until
  2890.           WSPCloseSocketWSPclosesocket() is invoked.
  2891.           
  2892. Comments  WSPShutdownWSPPSshutdown() does not block
  2893.           regardless of the SO_LINGER setting on the socket.
  2894.           An application should not rely on being able to re-
  2895.           use a socket after it has been shut down. In
  2896.           particular, a Winsock service provider is not
  2897.           required to support the use of WSPConnect() on
  2898.           such a socket.
  2899.  
  2900. Return Value   If no error occurs, WSPShutdownWSPshutdown()
  2901.           returns 0. Otherwise, a value of SOCKET_ERROR is
  2902.           returned, and a specific error code is available
  2903.           in lpErrno.
  2904.  
  2905. Error Codes                   WSANOTINITIALISED   A
  2906.                               successful PSStartup() must
  2907.                               occur before using this SPI.
  2908.           
  2909.           WSAENETDOWN         The network subsystem has
  2910.                               failed.
  2911.           
  2912.           WSAEINVAL           how is not valid, or is not
  2913.                               consistent with the socket
  2914.                               type, e.g., SD_SEND is used
  2915.                               with a UNI_RECV socket type.
  2916.           
  2917.           WSAEINPROGRESS      The function is invoked when a
  2918.                               callback is in progress.
  2919.           
  2920.           WSAENOTCONN         The socket is not connected
  2921.                               (connection-oriented sockets
  2922.                               only).
  2923.           
  2924.           WSAENOTSOCK         The descriptor is not a
  2925.                               socket.
  2926.  
  2927. See Also  WSPConnect(), WSPsocket().
  2928. 3.1.15 WSPsocket()
  2929. Description    Create a socket.
  2930.  
  2931.           #include <ws2spi.h>
  2932.  
  2933.           SOCKET PASCAL FAR WSPsocket ( int af, int type,
  2934.           int protocol, LPSTR lpszProviderKey, int FAR *
  2935.           lpErrno );
  2936.  
  2937.           
  2938.           af        An address family specification.  The
  2939.                     only format currently supported is
  2940.                     PF_INET, which is the ARPA Internet
  2941.                     address format.
  2942.           
  2943.           type      A type specification for the new socket.
  2944.           
  2945.           protocol  A particular protocol to be used with
  2946.                     the socket, or 0 if the caller does not
  2947.                     wish to specify a protocol.
  2948.           
  2949.           lpszProviderKey     A NULL-terminated string
  2950.                     identifying the Winsock service provider
  2951.                     to use. This information is useful to
  2952.                     provider implementations that present
  2953.                     multiple service provider appearances to
  2954.                     Winsock.
  2955.           
  2956.           lpErrno   A pointer to the error code.
  2957.  
  2958. Remarks   PSsocket() causes a socket descriptor and any
  2959.           related resources to be allocated and bound to a
  2960.           specific transport service provider.  If a
  2961.           protocol is not specified (i.e., equal to 0), the
  2962.           default for the specified socket type is used.
  2963.           However, the address family may be given as
  2964.           AF_UNSPEC (unspecified), in which case the
  2965.           protocol parameter must be specified.  The
  2966.           protocol number to use is particular to the
  2967.           "communication domain'' in which communication is
  2968.           to take place.  lpszProviderKey uniquely
  2969.           identifies the required transport service
  2970.           provider.
  2971.           
  2972.           All the socket created are in non-blocking mode.
  2973.           
  2974.           The following type specifications may be supported
  2975.           (all sockets are bi-directional unless specified
  2976.           otherwise):
  2977.           
  2978.            Type                    Explanation
  2979.            SOCK_STREAM             Alias for
  2980.                                     SOCK_REL_STREAM.
  2981.            
  2982.            SOCK_DGRAM              Alias for
  2983.                                     SOCK_UNREL_DGRAM.
  2984.            
  2985.            SOCK_SEQPACKET          Alias for
  2986.                                     SOCK_REL_DSTREAM.
  2987.            
  2988.            SOCK_RAW                Raw socket.
  2989.            
  2990.            SOCK_REL_STREAM         Connection-oriented
  2991.                                     reliable, unduplicated,
  2992.                                     sequenced, byte
  2993.                                     streamwith an out-of-
  2994.                                     band data transmission
  2995.                                     mechanism.  Uses TCP
  2996.                                     for the Internet
  2997.                                     address family.
  2998.            
  2999.            SOCK_REL_DSTREAM        Connection-oriented
  3000.                                     reliable, unduplicated,
  3001.                                     sequenced, message
  3002.                                     streamwith an out-of-
  3003.                                     band data transmission
  3004.                                     mechanism.
  3005.            
  3006.            SOCK_UNREL_DSTREAM      Connection-oriented
  3007.                                     unreliable,
  3008.                                     unduplicated,
  3009.                                     sequenced, message
  3010.                                     streamwith an out-of-
  3011.                                     band data transmission
  3012.                                     mechanism.
  3013.            
  3014.            SOCK_REL_UNISEND_DSTREAMConnection-oriented,
  3015.                                     reliable, one-way (send
  3016.                                     only), unduplicated,
  3017.                                     sequenced, message
  3018.                                     stream. The matching
  3019.                                     socket at the remote
  3020.                                     side need to be of
  3021.                                     style
  3022.                                     SOCK_REL_UNIRECV_DSTREA
  3023.                                     M.
  3024.            
  3025.            SOCK_REL_UNIRECV_DSTREAMConnection-oriented,
  3026.                                     reliable, one-way
  3027.                                     (receive only),
  3028.                                     unduplicated,
  3029.                                     sequenced, message
  3030.                                     stream.  The matching
  3031.                                     socket at the remote
  3032.                                     side need to be of
  3033.                                     style
  3034.                                     SOCK_REL_UNISEND_DSTREA
  3035.                                     M.
  3036.            
  3037.            SOCK_UNREL_UNISEND_DSTREAM   Connection-
  3038.                                     oriented, unreliable,
  3039.                                     one-way (send only),
  3040.                                     unduplicated,
  3041.                                     sequenced, message
  3042.                                     stream. The matching
  3043.                                     socket at the remote
  3044.                                     side need to be of
  3045.                                     style
  3046.                                     SOCK_UNREL_UNIRECV_DSTR
  3047.                                     EAM.
  3048.            
  3049.            SOCK_UNREL_UNIRECV_DSTREAM   Connection-
  3050.                                     oriented, unreliable,
  3051.                                     one-way (receive only),
  3052.                                     unduplicated,
  3053.                                     sequenced, message
  3054.                                     stream.  The matching
  3055.                                     socket at the remote
  3056.                                     side need to be of
  3057.                                     style
  3058.                                     SOCK_UNREL_UNISEND_DSTR
  3059.                                     EAM.
  3060.            
  3061.            SOCK_REL_DGRAM          Connectionless,
  3062.                                     reliable, datagram.
  3063.            
  3064.            SOCK_UNREL_DGRAM        Connectionless,
  3065.                                     unreliable, datagram.
  3066.            
  3067.            SOCK_REL_ISOCH_DSTREAM  Connection-oriented
  3068.                                     reliable, unduplicated,
  3069.                                     sequenced, isochronous,
  3070.                                     message streamwith an
  3071.                                     out-of-band data
  3072.                                     transmission mechanism.
  3073.            
  3074.            SOCK_UNREL_ISOCH_DSTREAMConnection-oriented
  3075.                                     unreliable,
  3076.                                     unduplicated,
  3077.                                     sequenced, isochronous,
  3078.                                     message streamwith an
  3079.                                     out-of-band data
  3080.                                     transmission mechanism.
  3081.            
  3082.            SOCK_UNREL_ISOCH_STREAM Connection-oriented
  3083.                                     unreliable,
  3084.                                     unduplicated,
  3085.                                     sequenced, isochronous,
  3086.                                     byte streamwith an out-
  3087.                                     of-band data
  3088.                                     transmission mechanism.
  3089.               
  3090.           
  3091.           Connection-oriented sockets such as
  3092.           SOCK_REL_STREAM provide full-duplex connections,
  3093.           and must be in a connected state before any data
  3094.           may be sent or received on them.  A connection to
  3095.           another socket is created with a WSPConnect()
  3096.           call.  Once connected, data may be transferred
  3097.           using WSPsend() and WSPrecv() calls.  When a
  3098.           session has been completed, a WSPclosesocket()
  3099.           must be performed.  Out-of-band data may also be
  3100.           transmitted as described in send() and received as
  3101.           described in recv().
  3102.           
  3103.           
  3104.           The communications protocols used to implement a
  3105.           reliable, connection-oriented socket ensure that
  3106.           data is not lost or duplicated.  If data for which
  3107.           the peer protocol has buffer space cannot be
  3108.           successfully transmitted within a reasonable
  3109.           length of time,  the connection is considered
  3110.           broken and subsequent calls will fail with the
  3111.           error code set to WSAETIMEDOUT.
  3112.           
  3113.           Connectionless, message-oriented sockets allow
  3114.           sending and receiving of datagrams to and from
  3115.           arbitrary peers using WSPsendto() and
  3116.           WSPrecvfrom().  If such a socket is WSPConnect()ed
  3117.           to a specific peer, datagrams may be send to that
  3118.           peer using WSPsend() and may be received from
  3119.           (only) this peer using WSPrecv().
  3120.  
  3121.  
  3122. Return Value   If no error occurs, WSPsocket() returns a
  3123.           descriptor referencing the new socket.  Otherwise,
  3124.           a value of INVALID_SOCKET is returned, and a
  3125.           specific error code is available in lpErrno.
  3126.  
  3127. Error Codes                   WSANOTINITIALISED   A
  3128.                               successful PSStartup() must
  3129.                               occur before using this SPI.
  3130.           
  3131.           WSAENETDOWN         The network subsystem has
  3132.                               failed.
  3133.           
  3134.           WSAEAFNOSUPPORT     The specified address family
  3135.                               is not supported.
  3136.           
  3137.           WSAEINPROGRESS      The function is invoked when a
  3138.                               callback is in progress.
  3139.           
  3140.           WSAEMFILE           No more socket descriptors are
  3141.                               available.
  3142.           
  3143.           WSAENOBUFS          No buffer space is available.
  3144.                               The socket cannot be created.
  3145.           
  3146.           WSAEPROTONOSUPPORT  The specified protocol is not
  3147.                               supported.
  3148.           
  3149.           WSAEPROTOTYPE       The specified protocol is the
  3150.                               wrong type for this socket.
  3151.           
  3152.           WSAESOCKTNOSUPPORT  The specified socket type is
  3153.                               not supported in this address
  3154.                               family.
  3155.  
  3156. See Also  WSPAccept, WSPbind(), WSPConnect(),
  3157.           WSPgetsockname(), WSPgetsockopt(),
  3158.           WSPsetsockopt(), WSPlisten(), WSPrecv(),
  3159.           WSPrecvfrom(), PSselect(), WSPsend(), WSPsendto(),
  3160.           WSPshutdown(), WSPioctlsocket().
  3161.  
  3162.  3.21.111 WSPAccept()
  3163.  
  3164. Description    Conditionally accept a connection based on
  3165.           the return value of a condition function, and
  3166.           optionally create and/or join a socket group.
  3167.  
  3168.           #include <ws2spi.h>
  3169.  
  3170.           SOCKET WSPAPI WSPAccept ( SOCKET s, struct
  3171.           sockaddr FAR * addr, int FAR * addrlen,
  3172.           LPCONDITIONPROC lpfnCondition, DWORD
  3173.           dwCallbackData,
  3174.           int FAR * lpAcceptAction,int FAR * lpErrno );
  3175.  
  3176.           
  3177.           s          A descriptor identifying a socket which
  3178.                     is listening for connections after a
  3179.                     WSPListenWSPlisten().
  3180.           
  3181.           addr      An optional pointer to a buffer which
  3182.                     receives the address of the connecting
  3183.                     entity, as known to the communications
  3184.                     layer. The exact format of the addr
  3185.                     argument is determined by the address
  3186.                     family established when the socket was
  3187.                     created.
  3188.           
  3189.           addrlen   An optional pointer to an integer which
  3190.                     contains the length of the address addr.
  3191.           
  3192.           lpfnCondition  The address of the optional, the
  3193.                     Winsock DLL-supplied condition function
  3194.                     which will make an accept/reject
  3195.                     decision based on the caller information
  3196.                     passed in as parameters, and optionally
  3197.                     create and/or join a socket group by
  3198.                     assigning appropriate value to the
  3199.                     result parameter g of this function.
  3200.           
  3201.           dwCallbackData The callback data passed back to
  3202.                     the Winsock DLL in the condition
  3203.                     function. This object is not interpreted
  3204.                     by the service providerWinsock
  3205.                     implementation.
  3206.           
  3207.           lpAcceptAction A optional pointer to the action
  3208.                     taken by the condition function.
  3209.           
  3210.           lpErrno   A pointer to the error code.
  3211.  
  3212. Remarks   This routine extracts the first connection on the
  3213.           queue of pending connections on s, and checks it
  3214.           against the condition function, provided the
  3215.           condition function is specified (i.e., not NULL).
  3216.           If lpfnCondition is set to NULL, a connection is
  3217.           accepted unconditionally, and no socket group is
  3218.           created or joined. If the condition function
  3219.           returns CF_ACCEPT, this routine creates a new
  3220.           socket with the same properties as s and returns a
  3221.           handle to the new socket, and then optionally
  3222.           creates and/or joins a socket group based on the
  3223.           value of the result parameter g in the condition
  3224.           function. If the condition function returns
  3225.           CF_REJECT, this routine rejects this connection
  3226.           request. The condition function runs in the same
  3227.           thread as this routine does, and should return as
  3228.           soon as possible. If the decision cannot be made
  3229.           immediately, the condition function willshould
  3230.           return CF_DEFER to indicate that no decision has
  3231.           been made, and no action about this connection
  3232.           request should be taken by the service provider.
  3233.           When the Winsock DLL is ready to take action on
  3234.           the connection request, it may invoke WSPAccept()
  3235.           again and return either CF_ACCEPT or CF_REJECT as
  3236.           a return value from the condition function.
  3237.           
  3238.           If no pending connections are present on the
  3239.           queue, and the socket is not marked as non-
  3240.           blocking, PSAcceptEx() blocks the caller until a
  3241.           connection is present.  If the socket is marked
  3242.           non-blocking and no pending connections are
  3243.           present on the queue, WSPAccept() returns an error
  3244.           as described below. The accepted socket may not be
  3245.           used to accept more connections. The original
  3246.           socket remains open.
  3247.           
  3248.           The argument addr is a result parameter that is
  3249.           filled in with the address of the connecting
  3250.           entity, as known to the communications layer. The
  3251.           exact format of the addr parameter is determined
  3252.           by the address family in which the communication
  3253.           is occurring. The addrlen is a value-result
  3254.           parameter; it should initially contain the amount
  3255.           of space pointed to by addr; on return it will
  3256.           contain the actual length (in bytes) of the
  3257.           address returned. This call is used with
  3258.           connection-oriented socket types such as
  3259.           SOCK_STREAM. If addr and/or addrlen are equal to
  3260.           NULL, then no information about the remote address
  3261.           of the accepted socket is returned. Otherwise,
  3262.           these two parameters will be filled in regardless
  3263.           of whether the condition function is specified or
  3264.           what it returns.
  3265.  
  3266.           The prototype of the condition function is as
  3267.           follows:
  3268.           
  3269.                int WSACALLBACK ConditionFunc( SOCKET s,
  3270.           LPWSABUF lpCallerId, LPWSABUF lpCallerData,
  3271.           LPWSABUF lpCalleeId, LPWSABUF lpCalleeData, GROUP
  3272.           FAR * g, DWORD dwCallbackData );
  3273.           
  3274.           LPWSABUF is defined in ws2spi.h as follows:
  3275.           
  3276.                typedef struct _WSABUF {
  3277.                     int       len;      // the length of the
  3278.           buffer
  3279.                     char FAR *     buf; // the pointer to
  3280.           the buffer
  3281.                } WSABUF, FAR * LPWSABUF;
  3282.           
  3283.           ConditionFunc is a placeholder for athe Winsock
  3284.           DLL supplied function pointername. The actual
  3285.           condition function must reside in a DLL or
  3286.           application module and be exported in the module
  3287.           definition file.  You must use MakeProcInstance()
  3288.           to get a procedure-instance address for the
  3289.           callback function.It is invoked in the same thread
  3290.           as WSPAccept(), thus no other Winsock functions
  3291.           can be called. The s parameter is the socket
  3292.           descriptor of the listening socket specified in
  3293.           PSAcceptEx().  The lpCallerId and lpCallerData are
  3294.           value parameters which contain the address of the
  3295.           connecting entity and any user data that was sent
  3296.           along with the connection request, respectively.
  3297.           The lpCalleeId is a value parameter which contains
  3298.           the local address of the connected entity. The
  3299.           lpCalleeData is a result parameter in which the
  3300.           condition function fills in the user data passed
  3301.           back to the connecting entity. lpCalleeData->len
  3302.           initially contains the length of the buffer
  3303.           allocated by the service provider, and 0 means
  3304.           user data back to the caller is not supported. If
  3305.           lpCalleeData->len is set to 0, no user data will
  3306.           be passed back. The exact format of the address
  3307.           and user data is specific to the address family to
  3308.           which the socket belongs.
  3309.           
  3310.           The result parameter g is assigned within the
  3311.           condition function to indicate the following
  3312.           actions:
  3313.                if g is an existing socket group id, add s to
  3314.           this group, provided all the
  3315.           requirements set by this group are met; or
  3316.                if g = SG_UNCONSTRAINED_GROUP, create an
  3317.           unconstrained socket               group and have
  3318.           s as the first member; or
  3319.                if g = SG_CONSTRAINED_GROUP, create a
  3320.           constrained socket group and            have s as
  3321.           the first member; or
  3322.                if g = NULL, no operation is performed.
  3323.           For unconstrained groups, any set of sockets may
  3324.           be grouped together as long as they are supported
  3325.           by a single Winsock service provider and are
  3326.           connection-oriented. A constrained socket group
  3327.           requires that connections on all grouped sockets
  3328.           be to the same host. For newly created socket
  3329.           groups, the new group id can be retrieved by
  3330.           lpGroupAction or using
  3331.           WSPGetSockOptWSPgetsockopt() with option
  3332.           SO_GROUP_ID, if this operation completes
  3333.           successfully.
  3334.           
  3335.           The lpAcceptAction is a result parameter which
  3336.           contains the action taken by the condition
  3337.           function, i.e., CF_ACCEPT, CF_REJECT, or CF_DEFER,
  3338.           if this function returns successfully.  If
  3339.           lpAcceptAction is set to NULL before calling this
  3340.           function, no information will be passed back.
  3341.           
  3342. Return Value   If no error occurs, WSPAccept() returns a
  3343.           value of type SOCKET which is a descriptor for the
  3344.           accepted socket. Otherwise, a value of
  3345.           INVALID_SOCKET is returned, and a specific error
  3346.           code is available in lpErrno.
  3347.  
  3348.           The integer referred to by addrlen initially
  3349.           contains the amount of space pointed to by addr.
  3350.           On return it will contain the actual length in
  3351.           bytes of the address returned.
  3352.  
  3353. Error Codes                   WSANOTINITIALISED   A
  3354.                               successful PSStartup() must
  3355.                               occur before using this API.
  3356.           
  3357.           WSAENETDOWN         The network subsystem has
  3358.                               failed.
  3359.           
  3360.           WSAECONNREFUSED     The connection request was
  3361.                               forcefully rejected as
  3362.                               indicated in the return value
  3363.                               of the condition function
  3364.                               (CF_REJECT).
  3365.           
  3366.           WSAEFAULT           The addrlen argument is too
  3367.                               small (less than the sizeof a
  3368.                               struct sockaddr) or the
  3369.                               lpfnCondition is not part of
  3370.                               the user address space.
  3371.           
  3372.           WSAEINPROGRESS      The function is invoked when a
  3373.                               callback is in progress.
  3374.           
  3375.           WSAEINVAL           WSPListenWSPlisten() was not
  3376.                               invoked prior to WSPAccept(),
  3377.                               parameter g specified in the
  3378.                               condition function is not a
  3379.                               valid value, the return value
  3380.                               of the condition function is
  3381.                               not a valid one, or any case
  3382.                               where the specified socket is
  3383.                               in an invalid state.
  3384.           
  3385.           WSAEMFILE           The queue is non-empty upon
  3386.                               entry to WSPAccept() and there
  3387.                               are no socket descriptors
  3388.                               available.
  3389.           
  3390.           WSAENOBUFS          No buffer space is available.
  3391.           
  3392.           WSAENOTSOCK         The descriptor is not a
  3393.                               socket.
  3394.           
  3395.           WSAEOPNOTSUPP       The referenced socket is not a
  3396.                               type that supports connection-
  3397.                               oriented service.
  3398.           
  3399.           WSATRY_AGAIN        The acceptance of the
  3400.                               connection request was
  3401.                               deferred as indicated in the
  3402.                               return value of the condition
  3403.                               function (CF_DEFER).
  3404.           
  3405.           WSAEWOULDBLOCK      No connections are present to
  3406.                               be accepted, or the connection
  3407.                               request that was deferred has
  3408.                               timed out or been withdrawn.
  3409.           
  3410. See Also  WSPAccept(), WSPBindWSPbind(), WSPConnect(),
  3411.           WSPGetSockOptWSPgetsockopt(),
  3412.           WSPListenWSPlisten(), WSPSelectWSPselect(),
  3413.           WSPsocket(), WSPEventSelect().
  3414. 3.1.2.12 WSPAsyncSelect32()
  3415.  
  3416. Description    Request event notification for a socket.
  3417. {For obvious reasons, this function description is
  3418. particularly bad about sounding like an API function
  3419. description instead of an SPI function description }
  3420.  
  3421.           #include <ws2spi.h>
  3422.  
  3423.           int WSPAPI WSPAsyncSelect32 ( SOCKET s, HWND hWnd,
  3424.           unsigned int wMsg, long lEvent, int FAR * lpErrno
  3425.           );
  3426.  
  3427.           
  3428.           s          A descriptor identifying the socket for
  3429.                     which event notification is required.
  3430.           
  3431.           hWnd      A handle identifying the window which
  3432.                     should receive a message when a network
  3433.                     event occurs.
  3434.           
  3435.           wMsg      The message to be received when a
  3436.                     network event occurs.
  3437.           
  3438.           lEvent    A bitmask which specifies a combination
  3439.                     of network events in which the
  3440.                     application is interested.
  3441.           
  3442.           lpErrno   A pointer to the error code.
  3443.  
  3444. Remarks   This function is only applicable to available in
  3445.           the 32-bit SPI. The 16 bit Winsock2.DLL uses
  3446.           WSPCallbackSelect() to implement the API function
  3447.           WSAAsyncSelect().
  3448.  
  3449.           This function is used to request that the service
  3450.           provider should send a message to the window hWnd
  3451.           whenever it detects any of the network events
  3452.           specified by the lEvent parameter. The message
  3453.           which should be sent is specified by the wMsg
  3454.           parameter. The socket for which notification is
  3455.           required is identified by s.
  3456.           
  3457.           This function automatically sets socket s to non-
  3458.           blocking mode, regardless of the value of lEvent.
  3459.           See WSPIoctlSocketWSPioctlsocket() about how to
  3460.           set the socket back to blocking mode.
  3461.           
  3462.           The lEvent parameter is constructed by or'ing any
  3463.           of the values specified in the following list.
  3464.  
  3465.                Value      Meaning
  3466.                FD_READ    Want to receive notification of
  3467.                           readiness for reading
  3468.                FD_WRITE   Want to receive notification of
  3469.                           readiness for writing
  3470.                FD_OOB     Want to receive notification of
  3471.                           the arrival of out-of-band data
  3472.                FD_ACCEPT  Want to receive notification of
  3473.                           incoming connections
  3474.                FD_CONNECT Want to receive notification of
  3475.                           completed connection
  3476.                FD_CLOSE   Want to receive notification of
  3477.                           socket closure
  3478.                FD_QOS     Want to receive notification of
  3479.                           socket Quality of Service (QOS)
  3480.                           changes
  3481.                FD_GROUP_QOS    Want to receive notification
  3482.                           of socket group Quality of
  3483.                           Service (QOS) changes
  3484.                
  3485.  
  3486.           Issuing a WSPAsyncSelect32() for a socket cancels
  3487.           any previous WSPAsyncSelect32() for the same
  3488.           socket. For example, to receive notification for
  3489.           both reading and writing, the Winsock DLL will
  3490.           application must call WSPAsyncSelect32() with both
  3491.           FD_READ and FD_WRITE, as follows:
  3492.           
  3493.           rc = WSPAsyncSelect32(s, hWnd, wMsg,
  3494.                     FD_READ|FD_WRITE, &error);
  3495.           
  3496.           It is not possible to specify different messages
  3497.           for different events. The following code will not
  3498.           work; the second call will cancel the effects of
  3499.           the first, and only FD_WRITE events will be
  3500.           reported with message wMsg2:
  3501.           
  3502.           rc = WSPAsyncSelect32WSAPsyncSelect(s, hWnd,
  3503.                     wMsg1, FD_READ, &error);
  3504.           rc = WSPAsyncSelect32WSAPsyncSelect(s, hWnd,
  3505.                     wMsg2, FD_WRITE, &error);
  3506.           
  3507.           To cancel all notification - i.e., to indicate
  3508.           that the service provider Winsock2 should send no
  3509.           further messages related to network events on the
  3510.           socket - lEvent should be set to zero.
  3511.           
  3512.           rc = WSPAsyncSelect32WSAPsyncSelect(s, hWnd, 0, 0,
  3513.                     &error);
  3514.           
  3515.           Although in this instance WSPAsyncSelect32()
  3516.           immediately disables event message posting for the
  3517.           socket, it is possible that messages may be
  3518.           waiting in the application's message queue. The
  3519.           application must therefore be prepared to receive
  3520.           network event messages even after cancellation.
  3521.           Closing a socket with WSPCloseSocketclosesocket()
  3522.           also cancels WSPAsyncSelect32() message sending,
  3523.           but the same caveat about messages in the queue
  3524.           prior to the WSPCloseSocketWSPclosesocket() still
  3525.           applies.
  3526.           
  3527.           Since a WSPAcceptWSPaccept()'ed socket has the
  3528.           same properties as the listening socket used to
  3529.           accept it, any WSPAsyncSelect32() events set for
  3530.           the listening socket apply to the accepted socket.
  3531.           For example, if a listening socket has
  3532.           WSPAsyncSelect32() events FD_ACCEPT, FD_READ, and
  3533.           FD_WRITE, then any socket accepted on that
  3534.           listening socket will also have FD_ACCEPT,
  3535.           FD_READ, and FD_WRITE events with the same wMsg
  3536.           value used for messages. If a different wMsg or
  3537.           events are desired, the application should call
  3538.           WSPAsyncSelect32(), passing the accepted socket
  3539.           and the desired new information.1
  3540.           
  3541.           When one of the nominated network events occurs on
  3542.           the specified socket s, the application's window
  3543.           hWnd receives message wMsg. The wParam argument
  3544.           identifies the socket on which a network event has
  3545.           occurred. The low word of lParam specifies the
  3546.           network event that has occurred. The high word of
  3547.           lParam contains any error code. The error code be
  3548.           any error as defined in Winsock2.h.
  3549.           
  3550.           The error and event codes may be extracted from
  3551.           the lParam using the macros WSAGETSELECTERROR and
  3552.           WSAGETSELECTEVENT, defined in Winsock2.h as:
  3553.           
  3554.           #define WSAGETSELECTERROR(lParam)
  3555.                     HIWORD(lParam)
  3556.           #define WSAGETSELECTEVENT(lParam)
  3557.                     LOWORD(lParam)
  3558.           
  3559.           The use of these macros will maximize the
  3560.           portability of the source code for the
  3561.           application.
  3562.           
  3563.           The possible network event codes which may be
  3564.           returned are as follows:
  3565.           
  3566.                Value      Meaning
  3567.                FD_READ    Socket s ready for reading
  3568.                FD_WRITE   Socket s ready for writing
  3569.                FD_OOB     Out-of-band data ready for
  3570.                           reading on socket s.
  3571.                FD_ACCEPT  Socket s ready for accepting a
  3572.                           new incoming connection
  3573.                FD_CONNECT Connection initiated on socket s
  3574.                           completed
  3575.                FD_CLOSE   Connection identified by socket s
  3576.                           has been closed
  3577.                FD_QOS     Quality of Service associated
  3578.                           with socket s has changed.
  3579.                FD_GROUP_QOS    Quality of Service
  3580.                           associated with the socket group
  3581.                           to which s belongs has changed.
  3582.                
  3583.           
  3584. Return Value   The return value is 0 if the application's
  3585.           declaration of interest in the network event set
  3586.           was successful. Otherwise the value SOCKET_ERROR
  3587.           is returned, and a specific error code is
  3588.           available in lpErrno.
  3589.  
  3590. Comments  Although WSPAsyncSelect32() can be called with
  3591.           interest in multiple events, the application
  3592.           window will receive a single message for each
  3593.           network event.
  3594.           
  3595.           As in the case of the WSPSelectWSPselect()
  3596.           function, WSPAsyncSelect32() will frequently be
  3597.           used to determine when a data transfer operation
  3598.           (WSPSendWSPsend() or WSPRecvWSPrecv()) can be
  3599.           issued with the expectation of immediate success.
  3600.           Nevertheless, a robust application must be
  3601.           prepared for the possibility that it may receive a
  3602.           message and issue a Winsock2 call which returns
  3603.           WSAEWOULDBLOCK immediately. For example, the
  3604.           following sequence of events is possible:
  3605.           
  3606.           (i)       data arrives on socket s; Winsock2 posts
  3607.                     WSPAsyncSelect32() message
  3608.           (ii)      application processes some other message
  3609.           (iii)     while processing, application issues an
  3610.                     WSPIoctlSocketWSPioctlsocket(s,
  3611.                     FIONREAD...) and notices that there is
  3612.                     data ready to be read
  3613.           (iv)      application issues a
  3614.                     WSPRecvWSPrecv(s,...) to read the data
  3615.           (v)       application loops to process next
  3616.                     message, eventually reaching the
  3617.                     WSPAsyncSelect32() message indicating
  3618.                     that data is ready to read
  3619.           (vi)      application issues
  3620.                     WSPRecvWSPrecv(s,...), which fails with
  3621.                     the error WSAEWOULDBLOCK.
  3622.           
  3623.           Other sequences are possible.
  3624.           
  3625.           The WinsockTheWinsock2 DLL will not continually
  3626.           flood an application with messages for a
  3627.           particular network event. Having successfully
  3628.           posted notification of a particular event to an
  3629.           application window, no further message(s) for that
  3630.           network event will be posted to the application
  3631.           window until the application makes the function
  3632.           call which implicitly reenables notification of
  3633.           that network event.
  3634.  
  3635.           Event          Re-enabling function
  3636.           FD_READ        WSPRecvWSPrecv() or
  3637.                          WSPRecvFromWSPrecvfrom()
  3638.           FD_WRITE       WSPSendWSPsend() or
  3639.                          WSPSendToWSPsendto() or
  3640.                          WSAGetBuffer()
  3641.           FD_OOB         WSPRecvWSPrecv()
  3642.           FD_ACCEPT      WSPAcceptWSPaccept() or
  3643.                          WSPAcceptEx()  unless the error
  3644.                          code returned is WSATRY_AGAIN
  3645.                          indicating that the condition
  3646.                          function returned CF_DEFER
  3647.           FD_CONNECT     NONE
  3648.           FD_CLOSE       NONE
  3649.           FD_QOS         WSPGetSockOptWSPgetsockopt() with
  3650.                          option SO_FLOWSPEC
  3651.           FD_GROUP_QOS   WSPGetSockOptWSPgetsockopt() with
  3652.                          option SO_GROUP_FLOWSPEC
  3653.           
  3654.           Any call to the reenabling routine, even one which
  3655.           fails, results in reenabling of message posting
  3656.           for the relevant event.
  3657.           
  3658.           For FD_READ, FD_OOB, FD_ACCEPT, FD_QOS and
  3659.           FD_GROUP_QOS events, message posting is "level-
  3660.           triggered." This means that if the reenabling
  3661.           routine is called and the relevant event is still
  3662.           valid after the call, a WSPAsyncSelect32() message
  3663.           is posted to the application. This allows an
  3664.           application to be event-driven and not be
  3665.           concerned with the amount of data that arrives at
  3666.           any one time. Consider the following sequence:
  3667.           
  3668.           (i)       network transport stack receives 100
  3669.                     bytes of data on socket s and causes
  3670.                     Winsock2 to post an FD_READ message.
  3671.           (ii)      The application issues WSPRecvWSPrecv(
  3672.                     s, buffptr, 50, 0) to read 50 bytes.
  3673.           (iii)     another FD_READ message is posted since
  3674.                     there is still data to be read.
  3675.           
  3676.           With these semantics, an application need not read
  3677.           all available data in response to an FD_READ
  3678.           message--a single WSPRecvWSPrecv() in response to
  3679.           each FD_READ message is appropriate. If an
  3680.           application issues multiple WSPRecvWSPrecv() calls
  3681.           in response to a single FD_READ, it may receive
  3682.           multiple FD_READ messages. Such an application may
  3683.           wish to disable FD_READ messages before starting
  3684.           the WSPRecvWSPrecv() calls by calling
  3685.           WSPAsyncSelect32() with the FD_READ event not set.
  3686.           
  3687.           If an event has already happened when the
  3688.           application calls WSPAsyncSelect32() or when the
  3689.           reenabling function is called, then a message is
  3690.           posted as appropriate. All the events have
  3691.           persistence beyond the occurrence of their
  3692.           respective events. For example, consider the
  3693.           following sequence: 1) an application calls
  3694.           WSPListenWSPlisten(), 2) a connect request is
  3695.           received but not yet accepted, 3) the application
  3696.           calls WSPAsyncSelect32() specifying that it wants
  3697.           to receive FD_ACCEPT messages for the socket. Due
  3698.           to the persistence of events, Winsock2 posts an
  3699.           FD_ACCEPT message immediately.
  3700.           
  3701.           The FD_WRITE event is handled slightly
  3702.           differently. An FD_WRITE message is posted when a
  3703.           socket is first connected with
  3704.           WSPConnectWSPconnect() or accepted with
  3705.           WSPAcceptWSPaccept(), and then after a
  3706.           WSPSendWSPsend() or WSPSendToWSPsendto(), or
  3707.           WSAGetBuffer() fails with WSAEWOULDBLOCK and
  3708.           buffer space becomes available. Therefore, an
  3709.           application can assume that sends are possible
  3710.           starting from the first FD_WRITE message and
  3711.           lasting until a send returns WSAEWOULDBLOCK. After
  3712.           such a failure the application will be notified
  3713.           that sends are again possible with an FD_WRITE
  3714.           message.
  3715.           
  3716.           The FD_OOB event is used only when a socket is
  3717.           configured to receive out-of-band data separately.
  3718.           If the socket is configured to receive out-of-band
  3719.           data in-line, the out-of-band (expedited) data is
  3720.           treated as normal data and the application should
  3721.           register an interest in, and will receive, FD_READ
  3722.           events, not FD_OOB events. An application may set
  3723.           or inspect the way in which out-of-band data is to
  3724.           be handled by using WSPSetSockOptWSPsetsockopt()
  3725.           or WSPGetSockOptWSPgetsockopt() for the
  3726.           SO_OOBINLINE option.
  3727.           
  3728.           The error code in an FD_CLOSE message indicates
  3729.           whether the socket close was graceful or abortive.
  3730.           If the error code is 0, then the close was
  3731.           graceful; if the error code is WSAECONNRESET, then
  3732.           the socket's virtual circuit was reset. This only
  3733.           applies to connection-oriented sockets such as
  3734.           SOCK_STREAM.
  3735.           
  3736.           The FD_CLOSE message is posted when a close
  3737.           indication is received for the virtual circuit
  3738.           corresponding to the socket. In TCP terms, this
  3739.           means that the FD_CLOSE is posted when the
  3740.           connection goes into the FIN WAIT or CLOSE WAIT
  3741.           states. This results from the remote end
  3742.           performing a WSPShutdownWSPshutdown() on the send
  3743.           side or a WSPCloseSocketWSPclosesocket().
  3744.           
  3745.           Please note your application will receive ONLY an
  3746.           FD_CLOSE message to indicate closure of a virtual
  3747.           circuit, and only when all the received data has
  3748.           been read if this is a graceful close. It will NOT
  3749.           receive an FD_READ message to indicate this
  3750.           condition.
  3751.           
  3752.           The FD_QOS or FD_GROUP_QOS message is posted when
  3753.           any field in the flow spec associated with socket
  3754.           s or the socket group that s belongs to has
  3755.           changed, respectively. Applications might use
  3756.           WSPGetSockOptWSPgetsocketopt() with option
  3757.           SO_FLOWSPEC or SO_GROUP_FLOWSPEC to get the
  3758.           current QOS for socket s or for the socket group s
  3759.           belongs to, respectively.
  3760.           
  3761. Error Codes                   WSAENETDOWN    The network
  3762.                               subsystem has failed.
  3763.           
  3764.           WSAEINVAL           Indicates that one of the
  3765.                               specified parameters was
  3766.                               invalid, or the specified
  3767.                               socket is in an invalid state.
  3768.           
  3769.           WSAEINPROGRESS      A blocking Winsock2 call is in
  3770.                               progress, or the service
  3771.                               provider is still processing a
  3772.                               callback function (see section
  3773.                               ???).
  3774.           
  3775.           WSAENOTSOCK         The descriptor is not a
  3776.                               socket.
  3777.  
  3778.           Additional error codes may be set when an
  3779.           application window receives a message. This error
  3780.           code is extracted from the lParam in the reply
  3781.           message using the WSAGETSELECTERROR macro.
  3782.           Possible error codes for each network event are:
  3783.           Event: FD_CONNECT
  3784.           Error Code          Meaning
  3785.           WSAEADDRINUSE       The specified address is
  3786.                               already in use.
  3787.           
  3788.           WSAEADDRNOTAVAIL    The specified address is not
  3789.                               available from the local
  3790.                               machine.
  3791.           
  3792.           WSAEAFNOSUPPORT     Addresses in the specified
  3793.                               family cannot be used with
  3794.                               this socket.
  3795.           
  3796.           WSAECONNREFUSED     The attempt to connect was
  3797.                               forcefully rejected.
  3798.           
  3799.           WSAENETUNREACH      The network can't be reached
  3800.                               from this host at this time.
  3801.           
  3802.           WSAENOBUFS          No buffer space is available.
  3803.                               The socket cannot be
  3804.                               connected.
  3805.           
  3806.           WSAETIMEDOUT        Attempt to connect timed out
  3807.                               without establishing a
  3808.                               connection
  3809.  
  3810.           Event: FD_CLOSE
  3811.           Error Code          Meaning
  3812.           WSAENETDOWN         The network subsystem has
  3813.                               failed.
  3814.           
  3815.           WSAECONNRESET       The connection was reset by
  3816.                               the remote side.
  3817.           
  3818.           WSAECONNABORTED     The connection was aborted due
  3819.                               to timeout or other failure.
  3820.           
  3821.           Event: FD_READ
  3822.           Event: FD_WRITE
  3823.           Event: FD_OOB
  3824.           Event: FD_ACCEPT
  3825.           Event: FD_QOS
  3826.           Event: FD_GROUP_QOS
  3827.           Error Code          Meaning
  3828.           WSAENETDOWN         The network subsystem has
  3829.                               failed.
  3830.           
  3831.  
  3832. See Also  WSPSelectWSPselect()
  3833. 3.1.2.13 WSPCallbackSelect16()
  3834.  
  3835. Description    Request event notification for a socket via
  3836.           the specified callback function.
  3837.  
  3838.           #include <ws2spi.h>
  3839.  
  3840.           int WSPAPI WSPCallbackSelect16 ( SOCKET s,
  3841.           LPSELECTPROC lpfnCallback,
  3842.           DWORD dwCallbackData, long lEvent, int FAR *
  3843.           lpErrno );
  3844.  
  3845.           s          A descriptor identifying the socket for
  3846.                     which event notification is required.
  3847.           
  3848.           lpfnCallback   The procedure instance address of
  3849.                     the callback function to be invoked by
  3850.                     Winsock service providers whenever a
  3851.                     registered network event happens.
  3852.           
  3853.           dwCallbackData The callback data which is passed
  3854.                     back to the application as a parameter
  3855.                     to the callback function. This object is
  3856.                     not interpreted by the Winsock service
  3857.                     provider.
  3858.           
  3859.           lEvent    A bitmask which specifies a combination
  3860.                     of network events in which the Winsock
  3861.                     DLL is interested.
  3862.           
  3863.           lpErrno   A pointer to the error code.
  3864.           
  3865.  
  3866. Remarks   This function is only applicable toavailable in
  3867.           the 16-bit SPI. The 16 bit Winsock2.DLL uses this
  3868.           function to implement the select(),
  3869.           WSAAsyncSelectWSAASyncSelect(), and
  3870.           WSPEventSelectWSAEventSelect() API functions.
  3871.           
  3872.           This function will enables the function-based
  3873.           callback mechanism for the specified socket. The
  3874.           callback function will be invoked whenever the
  3875.           service provider detects any of the network events
  3876.           specified by the lEvent parameter. The socket for
  3877.           which notification is required is identified by s.
  3878.           The value of dwCallbackData will be passed back to
  3879.           the callerapplication as a parameter to the
  3880.           callback function.
  3881.           
  3882.           This function automatically sets socket s to non-
  3883.           blocking mode.
  3884.           
  3885.           The prototype of the callback function is as
  3886.           follows:
  3887.           
  3888.                VOID WSACALLBACK CallbackFunc( SOCKET s, long
  3889.           lEvent, int    ErrorCode, DWORD dwCallbackData );
  3890.           
  3891.           CallbackFunc is a placeholder for athe Winsock DLL
  3892.           supplied function pointername. The actual callback
  3893.           function must reside in a DLL or application
  3894.           module and be exported in the module definition
  3895.           file.  You must use MakeProcInstance() to get a
  3896.           procedure-instance address for the callback
  3897.           function.  The callback function ismust be written
  3898.           in such a way that it can be called by the
  3899.           provider from within interrupt context2. (This
  3900.           means that the only Winsock SPI calls that may be
  3901.           made within the callback function are WSPSend(),
  3902.           WSPsend(), WSPSendTo(), WSPsendto(), WSPRecv(),
  3903.           WSPrecv(), and WSPRecvFrom() WSPrecvfrom()
  3904.           provided that the socket option SO_INTERRUPT for
  3905.           this socket s is TRUE and the MSG_INTERRUPT flag
  3906.           for these functions is set.)
  3907.           
  3908.           The lEvent parameter is constructed by or'ing any
  3909.           of the values specified in the following list.
  3910.  
  3911.                Value      Meaning
  3912.                FD_READ    Want to receive notification of
  3913.                           readiness for reading
  3914.                FD_WRITE   Want to receive notification of
  3915.                           readiness for writing
  3916.                FD_OOB     Want to receive notification of
  3917.                           the arrival of out-of-band data
  3918.                FD_ACCEPT  Want to receive notification of
  3919.                           incoming connections
  3920.                FD_CONNECT Want to receive notification of
  3921.                           completed connection
  3922.                FD_CLOSE   Want to receive notification of
  3923.                           socket closure
  3924.                FD_QOS     Want to receive notification of
  3925.                           Quality of Service (QOS) changes
  3926.                FD_GROUP_QOS    Want to receive notification
  3927.                           of socket group Quality of
  3928.                           Service (QOS) changes
  3929.                
  3930.                FD_CLEANUP     Want to receive notification
  3931.                          of completed clean-up operation
  3932.           Issuing a WSPCallbackSelect16() for a socket
  3933.           cancels any previous WSPCallbackSelect16() for the
  3934.           same socket. For example, to receive notification
  3935.           for both reading and writing, the Winsock DLL must
  3936.           call WSPCallbackSelect16() with both FD_READ and
  3937.           FD_WRITE, as follows:
  3938.           
  3939.           rc = WSPCallbackSelect16(s, lpfnCallback,
  3940.                     dwCallbackData, FD_READ|FD_WRITE,
  3941.                     lpErrno);
  3942.           
  3943.           It is not possible to specify different callback
  3944.           data for different events. The following code will
  3945.           not work; the second call will cancel the effects
  3946.           of the first, and only FD_WRITE events will be
  3947.           reported with dwCallbackData2:
  3948.           
  3949.           rc = WSPCallbackSelect16(s, lpfnCallback,
  3950.                     dwCallbackData1, FD_READ, lpErrno);
  3951.           rc = WSPCallbackSelect16(s, lpfnCallback,
  3952.                     dwCallbackData2, FD_WRITE, lpErrno);
  3953.           
  3954.           To cancel all notification - i.e., to indicate
  3955.           that the service provider should no long invoke
  3956.           the callback function related to network events on
  3957.           the socket - lEvent should be set to zero. In this
  3958.           case, lpfnCallback and dwCallbackData are ignored.
  3959.           
  3960.           rc = WSPCallbackSelect16(s, lpfnCallback,
  3961.                     dwCallbackData, 0, lpErrno);
  3962.           
  3963.           Closing a socket with
  3964.           WSPCloseSocketWSPclosesocket() also cancels
  3965.           WSPCallbackSelect16() mechanism on the socket.
  3966.           
  3967.           A WSPAccept()'ed socket has the same properties as
  3968.           the listening socket used to accept it except that
  3969.           no network events and callback function are
  3970.           associated with it. Winsock2.DLL will subsequently
  3971.           invoke WSPCallbackSelect16() to register interest
  3972.           in the appropriate set of events for the
  3973.           WSPAccept()'ed socket3.Since a PSAcceptEx()'ed
  3974.           socket has the same properties as the listening
  3975.           socket used to accept it, any PSCallbackSelect()
  3976.           events set for the listening socket apply to the
  3977.           accepted socket.  For example, if a listening
  3978.           socket has PSCallbackSelect() events FD_ACCEPT,
  3979.           FD_READ, and FD_WRITE, then any socket accepted on
  3980.           that listening socket will also have FD_ACCEPT,
  3981.           FD_READ, and FD_WRITE events with the same
  3982.           callback function.  If a different callback
  3983.           function or events are desired, PII.DLL should
  3984.           call PSCallbackSelect(), passing the accepted
  3985.           socket and the desired new information.
  3986.           
  3987.           When one of the nominated network events occurs on
  3988.           the specified socket s, the callback function will
  3989.           be invoked. The s argument identifies the socket
  3990.           on which a network event has occurred. The lEvent
  3991.           argument specifies the network event that has
  3992.           occurred. The ErrorCode argument contains any
  3993.           error code. The error code can be any error as
  3994.           defined in ws2spi.h.
  3995.           
  3996.           The possible network event codes which may be
  3997.           returned are as follows:
  3998.           
  3999.                Value      Meaning
  4000.                FD_READ    Socket s ready for reading
  4001.                FD_WRITE   Socket s ready for writing
  4002.                FD_OOB     Out-of-band data ready for
  4003.                reading on socket s.
  4004.                FD_ACCEPT  Socket s ready for accepting a
  4005.                           new incoming connection
  4006.                FD_CONNECT Connection initiated on socket s
  4007.                           completed
  4008.                FD_CLOSE   Connection identified by socket s
  4009.                           has been closed
  4010.                FD_QOS     Quality of Service associated
  4011.                           with socket s or the socket group
  4012.                           to which s belongs has been
  4013.                           changed.
  4014.                FD_GROUP_QOS    Quality of Service
  4015.                           associated with the socket group
  4016.                           to which s belongs has changed.
  4017.                
  4018.           
  4019. Return Value   The return value is 0 if the Winsock's
  4020.           declaration of interest in the network event set
  4021.           was successful. Otherwise the value SOCKET_ERROR
  4022.           is returned, and a specific error number is
  4023.           available in lpErrno.
  4024.  
  4025. Comments  Although WSPCallbackSelect16() can be called with
  4026.           interest in multiple events, the Winsock DLL will
  4027.           get a callback for each network event.
  4028.           
  4029.           As in the case of WSPSelectWSPselect(),
  4030.           WSPCallbackSelect16() isare frequently used to
  4031.           determine when a data transfer operation
  4032.           (WSPSendWSPPSsend() or WSPRecvWSPrecv()) can be
  4033.           issued with the expectation of immediate success.
  4034.           
  4035.           The Winsock service provider will not continually
  4036.           flood the Winsock DLL with callbacks for a
  4037.           particular network event on a given socket. Having
  4038.           successfully invoked a callback indicating a
  4039.           particular event to the Winsock DLL, no further
  4040.           callback(s) for that network event on the socket
  4041.           will be invoked to the Winsock DLL until the
  4042.           Winsock DLL makes the function call which
  4043.           implicitly reenables notification of that network
  4044.           event, and returns from the callback function4.
  4045.  
  4046.           Event          Re-enabling function
  4047.           FD_READ        WSPRecvWSPrecv() or
  4048.                          WSPRecvFromWSPrecvfrom()
  4049.           FD_WRITE       WSPSendWSPsend() or
  4050.                          WSPSendToWSPsendto() or
  4051.                          WSAGetBuffer()
  4052.           FD_OOB         WSPRecvWSPrecv()
  4053.           FD_ACCEPT      WSPAccept() unless the error code
  4054.                          returned is WSATRY_AGAIN indicating
  4055.                          that the condition function
  4056.                          returned CF_DEFER
  4057.           FD_CONNECT     NONE
  4058.           FD_CLOSE       NONE
  4059.           FD_QOS         WSPGetSockOptWSPgetsockopt() with
  4060.                          option SO_FLOWSPEC
  4061.           
  4062.           FD_GROUP_QOS   WSPGetSockOptWSPgetsockopt() with
  4063.                          option SO_GROUP_FLOWSPEC
  4064.           
  4065.           Any call to the reenabling routine, even one which
  4066.           fails (except in the case of FD_ACCEPT when
  4067.           WSPAccept() returns with error code WSATRY_AGAIN),
  4068.           results in reenabling of callback invocation for
  4069.           the relevant event.
  4070.           
  4071.           For FD_READ, FD_OOB, FD_ACCEPT, FD_QOS and
  4072.           FD_GROUP_QOS events, callback invocation is "level-
  4073.           triggered." This means that if the reenabling
  4074.           routine is called and the relevant event is still
  4075.           valid after the call, an additional callback is
  4076.           invoked after the previous callback returns. This
  4077.           allows applications using Winsock2.DLL to be event-
  4078.           driven and not be concerned with the amount of
  4079.           data that arrives at any one time. Consider the
  4080.           following sequence:
  4081.           
  4082.           (i)       The service provider receives 100 bytes
  4083.                     of data on socket s and invokes an
  4084.                     FD_READ callback.
  4085.           (ii)      The Winsock2.DLL issues WSPRecvWSPrecv(
  4086.                     s, buffptr, 50, 0, lpErrno) to read 50
  4087.                     bytes.
  4088.           (iii)     The service provider invokes another
  4089.                     FD_READ callback since there is still
  4090.                     data to be read.
  4091.           
  4092.           With these semantics, the Winsock DLL need not
  4093.           read all available data in response to an FD_READ
  4094.           callback--a single WSPRecvWSPrecv() in response to
  4095.           each FD_READ callback is appropriate. If the
  4096.           Winsock DLL issues multiple WSPRecvWSPrecv() calls
  4097.           in response to a single FD_READ, it may receive
  4098.           multiple FD_READ callbacks.
  4099.           
  4100.           If an event has already happened when the Winsock
  4101.           DLL calls WSPCallbackSelect16()5 or when the
  4102.           reenabling function is called, then a callback is
  4103.           invoked as appropriate. All the events have
  4104.           persistence beyond the occurrence of their
  4105.           respective events. For example, if the Winsock DLL
  4106.           calls WSPListenWSPlisten(), a connect attempt is
  4107.           made, then the Winsock DLL calls
  4108.           WSPCallbackSelect16() specifying that it wants to
  4109.           receive FD_ACCEPT callbacks for the socket, the
  4110.           service provider invokes an FD_ACCEPT callback
  4111.           immediately.
  4112.           
  4113.           The FD_WRITE event is handled slightly
  4114.           differently. An FD_WRITE callback is invoked when
  4115.           a socket is first connected with WSPConnect() or
  4116.           accepted with WSPAccept, and then after a
  4117.           WSPSendWSPsend() or WSPSendToWSPsendto(), or
  4118.           WSAGetBuffer() fails with WSAEWOULDBLOCK and
  4119.           buffer space becomes available. Therefore, the
  4120.           Winsock DLL can assume that sends are possible
  4121.           starting from the first FD_WRITE callback and
  4122.           lasting until a send returns WSAEWOULDBLOCK. After
  4123.           such a failure the Winsock DLL will be notified
  4124.           that sends are again possible with an FD_WRITE
  4125.           callback.
  4126.           
  4127.           The FD_OOB event is used only when a socket is
  4128.           configured to receive out-of-band data separately.
  4129.           If the socket is configured to receive out-of-band
  4130.           data in-line, the out-of-band (expedited) data is
  4131.           treated as normal data and the Winsock DLL should
  4132.           register an interest in, and will receive, FD_READ
  4133.           events, not FD_OOB events. The Winsock DLL may set
  4134.           or inspect the way in which out-of-band data is to
  4135.           be handled by using WSPSetSockOptWSPsetsockopt()
  4136.           or WSPGetSockOptWSPgetsockopt() for the
  4137.           SO_OOBINLINE option.
  4138.           
  4139.           The error code in an FD_CLOSE callback indicates
  4140.           whether the socket close was graceful or abortive.
  4141.           If the error code is 0, then the close was
  4142.           graceful; if the error code is WSAECONNRESET, then
  4143.           the socket's virtual circuit was reset. This only
  4144.           applies to connection-oriented sockets such as
  4145.           SOCK_STREAM.
  4146.           
  4147.           The FD_CLOSE callback is invoked when a close
  4148.           indication is received for the virtual circuit
  4149.           corresponding to the socket. In TCP terms, this
  4150.           means that the FD_CLOSE callback is invoked when
  4151.           the connection goes into the FIN WAIT or CLOSE
  4152.           WAIT states. This results from the remote end
  4153.           performing a WSPShutdownWSPshutdown() on the send
  4154.           side or a WSPCloseSocketWSPclosesocket().
  4155.           
  4156.           Please note the Winsock DLL shouldwill receive
  4157.           ONLY an FD_CLOSE callback to indicate closure of a
  4158.           virtual circuit. It shouldwill NOT receive an
  4159.           FD_READ callback to indicate this condition.
  4160.           
  4161.           The FD_QOS or FD_GROUP_QOS callback is invoked
  4162.           when any field in the flow spec associated with
  4163.           socket s or the socket group to which s belongs
  4164.           has changed, respectively. Winsock2.DLL should use
  4165.           WSPGetSockOptWSPgetsockopt() with option
  4166.           SO_FLOWSPEC or SO_GROUP_FLOWSPEC to get the
  4167.           current QOS for socket s or for the socket group
  4168.           to which s belongs, respectively.
  4169.  
  4170. Error Codes                   WSANOTINITIALISED   A
  4171.                               successful PSStartup() must
  4172.                               occur before using this API.
  4173.           
  4174.           WSAENETDOWN         The network subsystem has
  4175.                               failed.
  4176.           
  4177.           WSAEINVAL           Indicates that one of the
  4178.                               specified parameters was
  4179.                               invalid, or the specified
  4180.                               socket is in an invalid state.
  4181.           
  4182.           WSAEINPROGRESS      The function is invoked when a
  4183.                               callback is in progress.
  4184.           
  4185.           WSAEFAULT           The lpfnCallback is not part
  4186.                               of the user address space.
  4187.           
  4188.           WSAENOTSOCK         The descriptor is not a
  4189.                               socket.
  4190.  
  4191.           Additional error codes may be set when the Winsock
  4192.           DLL receives a callback. Possible error codes for
  4193.           each network event are:
  4194.           Event: FD_CONNECT
  4195.           Error Code          Meaning
  4196.           WSAEADDRINUSE       The specified address is
  4197.                               already in use.
  4198.           
  4199.           WSAEADDRNOTAVAIL    The specified address is not
  4200.                               available from the local
  4201.                               machine.
  4202.           
  4203.           WSAEAFNOSUPPORT     Addresses in the specified
  4204.                               family cannot be used with
  4205.                               this socket.
  4206.           
  4207.           WSAECONNREFUSED     The attempt to connect was
  4208.                               forcefully rejected.
  4209.           
  4210.           WSAEDESTADDRREQ     A destination address is
  4211.                               required.
  4212.           
  4213.           WSAEFAULT           The namelen argument is
  4214.                               incorrect.
  4215.           
  4216.           WSAEINVAL           The socket is already bound to
  4217.                               an address.
  4218.           
  4219.           WSAEISCONN          The socket is already
  4220.                               connected.
  4221.           
  4222.           WSAEMFILE           No more socket descriptors are
  4223.                               available.
  4224.           
  4225.           WSAENETUNREACH      The network can't be reached
  4226.                               from this host at this time.
  4227.           
  4228.           WSAENOBUFS          No buffer space is available.
  4229.                               The socket cannot be
  4230.                               connected.
  4231.           
  4232.           WSAENOTCONN         The socket is not connected.
  4233.           
  4234.           WSAENOTSOCK         The descriptor is not a
  4235.                               socket.
  4236.           
  4237.           WSAETIMEDOUT        Attempt to connect timed out
  4238.                               without establishing a
  4239.                               connection
  4240.  
  4241.           Event: FD_CLOSE
  4242.           Error Code          Meaning
  4243.           WSAENETDOWN         The network subsystem has
  4244.                               failed.
  4245.           
  4246.           WSAECONNRESET       The connection was reset by
  4247.                               the remote side.
  4248.           
  4249.           WSAECONNABORTED     The connection was aborted due
  4250.                               to timeout or other failure.
  4251.           
  4252.           Event: FD_READ
  4253.           Event: FD_WRITE
  4254.           Event: FD_OOB
  4255.           Event: FD_ACCEPT
  4256.           Event: FD_QOS
  4257.           Event: FD_GROUP_QOS
  4258.           Error Code          Meaning
  4259.           WSAENETDOWN         The network subsystem has
  4260.                               failed.
  4261.           
  4262. Notes For
  4263. Winsock Service
  4264. Providers When a socket is closed, the Winsock service
  4265.           provider should cancel any pending callbacks to
  4266.           the Winsock DLL.
  4267. 3.1.2.14 WSPCancelBlockingCall32()
  4268.  
  4269. Description    Cancel a blocking call which is currently in
  4270.           progress.
  4271.  
  4272.           #include <ws2spi.h>
  4273.  
  4274.           int WSPAPI WSPCancelBlockingCall32 ( int FAR *
  4275.           lpErrno );
  4276.           
  4277.           lpErrno   A pointer to the error code.
  4278.  
  4279. Remarks   This function is only applicable toavailable in
  4280. the 32-bit SPI.
  4281.           
  4282.           This function cancels any outstanding blocking
  4283.           operation for the current thread. It is normally
  4284.           used in two situations:
  4285.           
  4286.             1.   An application is processing a message which has been
  4287.                received while a blocking call is in progress. In this case,
  4288.                WSPIsBlocking32() will be TRUE.
  4289.             2.   A blocking call is in progress, and Winsock has called
  4290.                back to the applications "blocking hook" function (as
  4291.                established by WSPSetBlockingHook32()).
  4292.           
  4293.           In each case, the original blocking call will
  4294.           terminate as soon as possible with the error
  4295.           WSAEINTR. (In (1), the termination will not take
  4296.           place until Windows message scheduling has caused
  4297.           control to revert to the blocking routine in
  4298.           Windows Sockets. In (2), the blocking call will be
  4299.           terminated as soon as the blocking hook function
  4300.           completes.)
  4301.           
  4302.           In the case of a blocking WSPConnect() operation,
  4303.           the Windows Sockets implementation will terminate
  4304.           the blocking call as soon as possible, but it may
  4305.           not be possible for the socket resources to be
  4306.           released until the connection has completed (and
  4307.           then been reset) or timed out. This is likely to
  4308.           be noticeable only if the application immediately
  4309.           tries to open a new socket (if no sockets are
  4310.           available), or to WSPConnect() to the same peer.
  4311.           
  4312.           Cancelling an WSPAccept() or a
  4313.           WSPSelectWSPselect() call does not adversely
  4314.           impact the sockets passed to these calls. Only the
  4315.           particular call fails; any operation that was
  4316.           legal before the cancel is legal after the cancel,
  4317.           and the state of the socket is not affected in any
  4318.           way.
  4319.           
  4320.           Cancelling any operation other than WSPAaccept()
  4321.           and WSPSelectWSPselect() can leave the socket in
  4322.           an indeterminate state. If an application cancels
  4323.           a blocking operation on a socket, the only
  4324.           operation that the application can depend on being
  4325.           able to perform on the socket is a call to
  4326.           WSPCloseSocketWSPclosesocket(), although other
  4327.           operations may work on some service provider
  4328.           Windows Sockets implementations. If an application
  4329.           desires maximum portability, it must be careful
  4330.           not to depend on performing operations after a
  4331.           cancel. An application may reset the connection by
  4332.           setting the timeout on SO_LINGER to 0.
  4333.           
  4334.           If a cancel operation compromised the integrity of
  4335.           a SOCK_STREAM's data stream in any way, the
  4336.           Windows Sockets implementation must reset the
  4337.           connection and fail all future operations other
  4338.           than WSPCloseSocketWSPclosesocket() with
  4339.           WSAECONNABORTED.
  4340.  
  4341. Return Value   The return value is 0 if the blocking
  4342.           operation has been successfully cancelled.
  4343.           Otherwise the value SOCKET_ERROR is returned, and
  4344.           a specific error number is available in lpErrno.
  4345.           On a blocking socket, the return value indicates
  4346.           success or failure of the connection attempt.
  4347.           
  4348.  
  4349. Comments  Note that it is possible that the network
  4350.           operation completes before the
  4351.           WSPCancelBlockingCall32() is processed, for
  4352.           example if data is received into the user buffer
  4353.           at interrupt time while the application is in a
  4354.           blocking hook. In this case, the blocking
  4355.           operation will return successfully as if
  4356.           WSPCancelBlockingCall32() had never been called.
  4357.           Note that the WSPCancelBlockingCall32() still
  4358.           succeeds in this case; the only way to know with
  4359.           certainty that an operation was actually canceled
  4360.           is to check for a return code of WSAEINTR from the
  4361.           blocking call.
  4362.  
  4363. Error Codes                   WSANOTINITIALISED   A
  4364.                               successful WSPStartup() must
  4365.                               occur before using this SPI.
  4366.           
  4367.           WSAENETDOWN         The Windows Sockets
  4368.                               implementation has detected
  4369.                               that the network subsystem has
  4370.                               failed.
  4371.           
  4372.           WSAEINVAL           Indicates that there is no
  4373.                               outstanding blocking call.
  4374.           
  4375.           WSAEINPROGRESS      A blocking PII operation is in
  4376.                               progress.
  4377.  
  4378. See Also  WSPIsBlocking32(), WSPSetBlockingHook32(),
  4379.           WSPUnhookBlockingHook32()
  4380. PSCancelBlockingCall()
  4381. Description    Cancel a blocking call which is currently in
  4382.           progress.
  4383.  
  4384.           #include <PII.h>
  4385.  
  4386.           int PASCAL FAR PSCancelBlockingCall ( void );
  4387.  
  4388. Remarks   This function cancels any outstanding blocking
  4389.           operation for this task.  It is normally used in
  4390.           two situations:
  4391.           
  4392.           (1) An application is processing a message which
  4393.           has been received while a blocking call is in
  4394.           progress.  In this case, PSIsBlocking() will be
  4395.           true.
  4396.           
  4397.           (2) A blocking call is in progress, and PII has
  4398.           called back to the application's "blocking hook"
  4399.           function (as established by PSSetBlockingHook()).
  4400.           
  4401.           In each case, the original blocking call will
  4402.           terminate as soon as possible with the error
  4403.           WSAEINTR.  (In (1), the termination will not take
  4404.           place until Windows message scheduling has caused
  4405.           control to revert to the blocking routine in PII.
  4406.           In (2), the blocking call will be terminated as
  4407.           soon as the blocking hook function completes.)
  4408.           
  4409.           In the case of a blocking PSconnect() operation,
  4410.           the PII Service Provider will terminate the
  4411.           blocking call as soon as possible, but it may not
  4412.           be possible for the socket resources to be
  4413.           released until the connection has completed (and
  4414.           then been reset) or timed out.  This is likely to
  4415.           be noticeable only if the application immediately
  4416.           tries to open a new socket (if no sockets are
  4417.           available), or to PSconnect() to the same peer.
  4418.           
  4419.           Canceling an PSaccept() or a PSselect() call does
  4420.           not adversely impact the sockets passed to these
  4421.           calls.  Only the particular call fails; any
  4422.           operation that was legal before the cancel is
  4423.           legal after the cancel, and the state of the
  4424.           socket is not affected in any way.
  4425.           
  4426.           Canceling any operation other than PSaccept() and
  4427.           PSselect() can leave the socket in an
  4428.           indeterminate state.  If an application cancels a
  4429.           blocking operation on a socket, the only operation
  4430.           that the application can depend on being able to
  4431.           perform on the socket is a call to
  4432.           PSclosesocket(), although other operations may
  4433.           work on some PII Service Providers.  If an
  4434.           application desires maximum portability, it must
  4435.           be careful not to depend on performing operations
  4436.           after a cancel.  An application may reset the
  4437.           connection by setting the timeout on SO_LINGER to
  4438.           0.
  4439.           
  4440.           If a cancel operation compromised the integrity of
  4441.           a SOCK_STREAM's data stream in any way, the PII
  4442.           Service Provider must reset the connection and
  4443.           fail all future operations other than
  4444.           PSclosesocket() with WSAECONNABORTED.
  4445.  
  4446. Return Value   The value returned by PSCancelBlockingCall()
  4447.           is 0 if the operation was successfully canceled.
  4448.           Otherwise the value SOCKET_ERROR is returned, and
  4449.           a specific error number may be retrieved by
  4450.           calling PSGetLastError().
  4451.  
  4452. Comments  Note that it is possible that the network
  4453.           operation completes before the
  4454.           PSCancelBlockingCall()  is processed, for example
  4455.           if data is received into the user buffer at
  4456.           interrupt time while the application is in a
  4457.           blocking hook.  In this case, the blocking
  4458.           operation will return successfully as if
  4459.           PSCancelBlockingCall() had never been called.
  4460.           Note that the PSCancelBlockingCall() still
  4461.           succeeds in this case; the only way to know with
  4462.           certainty that an operation was actually canceled
  4463.           is to check for a return code of WSAEINTR from the
  4464.           blocking call.
  4465.  
  4466. Error Codes                   WSANOTINITIALISED   A
  4467.                               successful PSStartup() must
  4468.                               occur before using this SPI.
  4469.           
  4470.           WSAENETDOWN         The PII Service Provider has
  4471.                               detected that the network
  4472.                               subsystem has failed.
  4473.           
  4474.           WSAEINVAL           Indicates that there is no
  4475.                               outstanding blocking call.
  4476.  
  4477. 3.1.2.15 WSPCleanup()
  4478.  
  4479. Description    Terminate use of the Winsock service
  4480.           provider.
  4481.  
  4482.           #include <ws2spi.h>
  4483.  
  4484.           int WSPAPI WSPCleanup ( LPCLEANUPPROC
  4485.           lpfnCallback, DWORD dwCallbackData, int FAR *
  4486.           lpErrno );
  4487.           
  4488.           lpfnCallback   The address of the callback
  4489.                     function to be invoked by the service
  4490.                     provider when the cleanup operation
  4491.                     completed.
  4492.           
  4493.           dwCallbackData The callback data passed back to
  4494.                     the Winsock DLL along with the callback.
  4495.                     This object is not interpreted by the
  4496.                     Winsock service provider.
  4497.           
  4498.           lpErrno   A pointer to the error code.
  4499.  
  4500. Remarks   The Winsock DLL is required to perform a
  4501.           (successful) WSPStartup() call before it can use
  4502.           Winsock service providers. When it has completed
  4503.           the use of Winsock service providers, the Winsock
  4504.           DLL must call WSPCleanup() to deregister itself
  4505.           from a Winsock service provider and allow the
  4506.           service provider to free any resources allocated
  4507.           on behalf of the Winsock DLL. Any open connection-
  4508.           oriented sockets that are connected when
  4509.           WSPCleanup() is called are reset; sockets which
  4510.           have been closed with
  4511.           WSPCloseSocketWSPclosesocket() but which still
  4512.           have pending data to be sent are not affected--the
  4513.           pending data is still sent. When the cleanup
  4514.           operation is finished, the specified callback
  4515.           function will be invoked. The value of
  4516.           dwCallbackData will be passed back to the Winsock
  4517.           DLL along with the callback.
  4518.           
  4519.           The prototype of the callback function is as
  4520.           follows:
  4521.           
  4522.                VOID WSACALLBACK CallbackFunc( int ErrorCode,
  4523.           DWORD dwCallbackData );
  4524.           
  4525.           CallbackFunc is a placeholder for athe Winsock DLL-
  4526.           supplied function pointername. The callback
  4527.           function is only called when the client thread
  4528.           that invoked this SPI is blocked in an alertable
  4529.           wait. The callback data is passed back to the
  4530.           Winsock DLL along with the callback. This object
  4531.           is not interpreted by the Winsock service
  4532.           provider.
  4533.           
  4534.           {I'm not convinced this is sufficient. Perhaps if
  4535.           the first call to WSPCleanup() returns
  4536.           WSAEWOULDBLOCK, then the Winsock DLL must wait for
  4537.           the callback to be invoked before unloading the
  4538.           provider DLL. Under Win32, the Winsock DLL would
  4539.           need to be blocked in an alertable wait for the
  4540.           callback (really a user-mode APC) to be invoked.
  4541.           The callback routine (in the Winsock DLL) could
  4542.           signal an event, waking the main thread. The main
  4543.           thread could then unload the DLL. Just a
  4544.           thought...}
  4545.           
  4546.           There must be a call to PSCleanup() for every call
  4547.           to PSStartup() made by a task.  Only the final
  4548.           PSCleanup() for that task does the actual cleanup;
  4549.           the preceding calls simply decrement an internal
  4550.           reference count in the PII service provider.  A
  4551.           naive application may ensure that PSCleanup() was
  4552.           called enough times by calling PSCleanup() in a
  4553.           loop until it returns WSANOTINITIALISED.
  4554.  
  4555. Return Value   The return value is 0 if the operation has
  4556.           been successfully initiated. Otherwise the value
  4557.           SOCKET_ERROR is returned, and a specific error
  4558.           number is available in lpErrno.
  4559.           On a blocking socket, the return value indicates
  4560.           success or failure of the connection attempt.
  4561.           
  4562.  
  4563. Comments  Attempting to call PSCleanup() from within a
  4564.           blocking hook and then failing to check the return
  4565.           code is a common PII programming error.  If an
  4566.           application needs to quit while a blocking call is
  4567.           outstanding, the application must first cancel the
  4568.           blocking call with PSCancelBlockingCall() then
  4569.           issue the PSCleanup() call once control has been
  4570.           returned to the application.
  4571.  
  4572. Notes For
  4573. Winsock Service
  4574. Providers The Winsock DLL will make one and only one
  4575.           WSPCleanup() call to indicate deregistration from
  4576.           a Winsock service provider. This function can
  4577.           thus, for example, be utilized to free up
  4578.           allocated resources. {Yeah, but since each
  4579.           protocol is represented as a separate service
  4580.           provider, it's possible that the service
  4581.           provider's DLL which implements multiple protocols
  4582.           (e.g. TCP and UDP) could be called with
  4583.           WSPCleanup() multiple times} {We have basically
  4584.           two choices here. We could either a) make separate
  4585.           WSPStartup() and WSPCleanup() calls for each
  4586.           protocol/address_family/socket_type triple
  4587.           supported by a given service provider DLL, or b)
  4588.           provide a single WSPStartup() call when a service
  4589.           provider is first loaded, and a single
  4590.           WSPCleanup() when its time to close shop. I tend
  4591.           to favorfavour b), as it places the burden of
  4592.           responsibility on the Winsock DLL, where it's
  4593.           easier to control & get right (once).}
  4594.  
  4595.           A PII service provider must be prepared to deal
  4596.           with an application which terminates without
  4597.           invoking PSCleanup() - for example, as a result of
  4598.           an error.
  4599.           
  4600.           In a multithreaded environment, WSPCleanup()
  4601.           terminates Winsock operations for all threads.
  4602.           
  4603.           A Winsock service provider must ensure that
  4604.           WSPCleanup() leaves things in a state in which the
  4605.           Winsock DLL can invoke WSPStartup() to re-
  4606.           establish Winsock usage.
  4607.  
  4608. Error Codes                   WSANOTINITIALISED   A
  4609.                               successful PSStartup() must
  4610.                               occur before using this SPI.
  4611.           
  4612.           WSAENETDOWN         The network subsystem has
  4613.                               failed.
  4614.           
  4615.           WSAEFAULT           The lpfnCallback is not part
  4616.                               of the user address space.
  4617.           
  4618.           WSAEINPROGRESS      A blocking PII operation is in
  4619.                               progress.
  4620.  
  4621. See Also  WSPStartup()
  4622. 3.1.2.16 WSPConnect()
  4623.  
  4624. Description    Establish a connection to a peer, create
  4625.           and/or join a socket group, and specify needed
  4626.           quality of service based on the supplied flow
  4627.           spec.
  4628.  
  4629.           #include <ws2spi.h>
  4630.  
  4631.           int WSPAPI WSPConnect ( SOCKET s, const struct
  4632.           sockaddr FAR * name, int namelen, LPWSABUF
  4633.           lpCallerData, LPWSABUF lpCalleeData, GROUP g,
  4634.           LPQOS lpSFlowspec, int iSFlowspecLen, LPQOS
  4635.           lpGFlowspec, int iGFlowspecLen, int FAR * lpErrno
  4636.           );
  4637.  
  4638.           
  4639.           s          A descriptor identifying an unconnected
  4640.                     socket.
  4641.           
  4642.           name      The name of the peer to which the socket
  4643.                     is to be connected.
  4644.           
  4645.            namelen  The length of the name.
  4646.           
  4647.           lpCallerData   A pointer to the user data that is
  4648.                     to be transferred to the peer during
  4649.                     connection establishment.
  4650.           
  4651.           lpCalleeData   A pointer to the user data that is
  4652.                     to be transferred back from the peer
  4653.                     during connection establishment.
  4654.           
  4655.           g         The identifier of the socket group.
  4656.           
  4657.           lpSFlowspec    A pointer to the flow specs for
  4658.                     socket s, one for each direction, if s
  4659.                     is a DSTREAM type socket. Otherwise,
  4660.                     this parameter is ignored.
  4661.           
  4662.           iSFlowspecLen  The length of the flow spec for
  4663.                     socket s, if s is unidirectional and
  4664.                     DSTREAM type socket.  Otherwise, this
  4665.                     parameter is ignored.
  4666.           
  4667.           lpGFlowspec    A pointer to the flow specs for the
  4668.                     socket group to be created, one for each
  4669.                     direction, if the value of parameter g
  4670.                     is SG_CONSTRAINED_GROUP. Otherwise, this
  4671.                     parameter is ignored.
  4672.           
  4673.           lpErrno   A pointer to the error code.
  4674.           
  4675.           iGFlowspecLen  The length of the flow spec for the
  4676.                     socket group to be created, if the value
  4677.                     of parameter g is SG_CONSTRAINED_GROUP.
  4678.                     Otherwise, this parameter is ignored.
  4679.  
  4680. Remarks   This function is used to create a connection to
  4681.           the specified destination, and to perform a number
  4682.           of other ancillary operations that occur at
  4683.           connect time as well. For connection-oriented
  4684.           sockets (e.g., type SOCK_STREAM), an active
  4685.           connection is initiated to the foreign host using
  4686.           name (an address in the name space of the socket;
  4687.           for a detailed description, please see
  4688.           WSPBindWSPbind()). When this call completes
  4689.           successfully, the socket is ready to send/receive
  4690.           data.
  4691.           
  4692.           For a connectionless socket (e.g., type
  4693.           SOCK_UNREL_DGRAM), the operation performed by
  4694.           WSPConnect() is merely to establish a default
  4695.           destination address which will be used on
  4696.           subsequent WSPSendWSPsend() and WSPRecvWSPrecv()
  4697.           calls. Exchange of user to user data and QOS
  4698.           specification are not possible and the
  4699.           corresponding parameters will be ignored.
  4700.           
  4701.           If the socket, s, is unbound, unique values are
  4702.           assigned to the local association by the system,
  4703.           and the socket is marked as bound. Note that if
  4704.           the address field of the name structure is all
  4705.           zeroes, WSPConnect() will return the error
  4706.           WSAEADDRNOTAVAIL.
  4707.           
  4708.           The Winsock DLL is responsible for allocating any
  4709.           memory space pointed to directly or indirectly by
  4710.           any of the parameters it specified. LPWSABUF and
  4711.           LPQOS are defined in ws2spi.h as follows:
  4712.           
  4713.                typedef struct _WSABUF {
  4714.                     int       len;      // the length of the
  4715.           buffer
  4716.                     char FAR *     buf; // the pointer to
  4717.           the buffer
  4718.                } WSABUF, FAR * LPWSABUF;
  4719.           
  4720.                typedef enum
  4721.                {
  4722.                     GuaranteedService,
  4723.                     BestEffortService
  4724.                } GUARANTEE;
  4725.  
  4726.                typedef struct _flowparams
  4727.                {
  4728.                     int64          AverageBandwidth;// In
  4729. Bytes/sec
  4730.                          int64          PeakBandwidth; // In
  4731. Bytes/sec
  4732.                          int64          BurstLength;   // In
  4733. microseconds
  4734.                     int64          Latency;       // In
  4735. microseconds
  4736.                     int64          DelayVariation;     // In
  4737. microseconds
  4738.                     GUARANTEE levelOfGuarantee;// Guaranteed
  4739. or
  4740.                                         // Best Effort
  4741.                     int32          CostOfCall;    //
  4742. Reserved for future
  4743.                                         // use, must be set
  4744. to 0
  4745.                     int32          ProviderId;    //
  4746. Provider Identifier
  4747.                     int32          SizePSP;  // Length of
  4748. provider
  4749.                                         // specific
  4750. parameters
  4751.                          UCHAR
  4752. ProviderSpecificParams[1];// provider specific
  4753. // parameters
  4754.                } FLOWPARAMS;
  4755.  
  4756.                typedef struct _QualityOfService
  4757.                {
  4758.                     FLOWPARAMS     ForwardFP;     //
  4759. Caller(Initiator) to callee
  4760.                     FLOWPARAMS     BackwardFP;    // Callee
  4761. to caller
  4762.                } QOS, FAR * LPQOS;
  4763.           
  4764.           The lpCallerData is a value parameter which
  4765.           contains any user data that is to be sent along
  4766.           with the connection request. If lpCallerData is
  4767.           NULL, no user data will be passed to the peer. The
  4768.           lpCalleeData is a result parameter which will
  4769.           contain any user data passed back from the peer as
  4770.           part of the connection establishment. If
  4771.           lpCalleeData->len is 0, no user data has been
  4772.           passed back. The lpCalleeData information will be
  4773.           valid when the connection operation is complete,
  4774.           i.e., after the FD_CONNECT notification has
  4775.           occurred. If lpCalleeData is NULL, no user data
  4776.           will be passed back. The exact format of the user
  4777.           data is specific to the address family to which
  4778.           the socket belongs.
  4779.           
  4780.           Parameter g is used to indicate the appropriate
  4781.           actions on socket groups:
  4782.                if g is an existing socket group id, add s to
  4783.           this group, provided all the
  4784.           requirements set by this group are met; or
  4785.                if g = SG_UNCONSTRAINED_GROUP, create an
  4786.           unconstrained socket               group and have
  4787.           s as the first member; or
  4788.                if g = SG_CONSTRAINED_GROUP, create a
  4789.           constrained socket group and            have s as
  4790.           the first member; or
  4791.                if g = NULL, no operation is performed, and
  4792.           is equivalent to connect().
  4793.           For unconstrained group, any set of sockets may be
  4794.           grouped together as long as they are supported by
  4795.           a single Winsock service provider and are
  4796.           connection-oriented. A constrained socket group
  4797.           requires that connections on all grouped sockets
  4798.           be to the same host. For newly created socket
  4799.           groups, the new group id can be retrieved by using
  4800.           WSPGetSockOptWSPgetsockopt() with option
  4801.           SO_GROUP_ID, if this operation completes
  4802.           successfully.
  4803.           
  4804.           lpSFlowspec, and iSFlowspecLen specifies two
  4805.           blocks of memory containing the flow specs for
  4806.           socket s, one for each direction, if s is a
  4807.           DSTREAM type socket. Otherwise, these values are
  4808.           ignored. The forward QOS or backward QOS values
  4809.           will be ignored as appropriate for unidirectional
  4810.           sockets. for UNI_RECV type socket. The backward
  4811.           QOS value will be ignored for UNI_SEND type
  4812.           socket. The first part of each memory block is
  4813.           struct FLOWSPEC, optionally followed by any
  4814.           service provider specific portion. Thus,
  4815.           lpSFlowspec->Flen and lpSFlowspec->Blen must be
  4816.           larger than or equal to the size of struct
  4817.           FLOWSPEC. A NULL value for lpSFlowspec indicates
  4818.           no application supplied flow spec.
  4819.           
  4820.           lpGFlowspec, and iGFlowspecLen specifies two
  4821.           blocks of memory containing the flow specs for the
  4822.           socket group to be created, one for each
  4823.           direction, provided that the value of parameter g
  4824.           is SG_CONSTRAINED_GROUP. Otherwise, these values
  4825.           are ignored. The first part of each memory block
  4826.           is struct FLOWSPEC, optionally followed by any
  4827.           service provider specific portion. Thus,
  4828.           lpGFlowspec->Flen and lpGFlowspec->Blen must be
  4829.           larger than or equal to the size of struct
  4830.           FLOWSPEC. A NULL value for lpGFlowspec indicates
  4831.           no application supplied flow spec.
  4832.           
  4833. Comments  When connected sockets break (i.e. become closed
  4834.           for whatever reason), they should be discarded and
  4835.           recreated. It is safest to assume that when things
  4836.           go awry for any reason on a connected socket, the
  4837.           Winsock DLL must discard and recreate the needed
  4838.           sockets in order to return to a stable point.
  4839.  
  4840. Return Value   If no error occurs, WSPConnect() returns 0.
  4841.           Otherwise, it returns SOCKET_ERROR, and a specific
  4842.           error code is available in lpErrno.
  4843.  
  4844.           On a blocking socket, the return value indicates
  4845.           success or failure of the connection attempt.
  4846.           
  4847. Error Codes    The following errors may occur at the time of
  4848.           the function call, and indicate that the connect
  4849.           operation could not be initiated.
  4850.  
  4851. WSANOTINITIALISED             A successful PSStartup() must
  4852.                               occur before using this SPI.
  4853.           
  4854.           WSAENETDOWN         The network subsystem has
  4855.                               failed.
  4856.           
  4857.           WSAEADDRINUSE       The specified address is
  4858.                               already in use.
  4859.           
  4860.           WSAEINTR            The (blocking) call was
  4861.                               canceled via
  4862.                               PSCancelBlockingCall().
  4863.           
  4864.           WSAEINPROGRESS      The function is invoked when a
  4865.                               callback is in progress.
  4866.           
  4867.           WSAEADDRNOTAVAIL    The specified address is not
  4868.                               available from the local
  4869.                               machine.
  4870.           
  4871.           WSAEAFNOSUPPORT     Addresses in the specified
  4872.                               family cannot be used with
  4873.                               this socket.
  4874.           
  4875.           WSAEDESTADDREQ      A destination address is
  4876.                               required.
  4877.           
  4878.           WSAEFAULT           The namelen argument is
  4879.                               incorrect, the buffer length
  4880.                               for lpCalleeData, lpSFlowspec,
  4881.                               and lpGFlowspec are too small,
  4882.                               or the buffer length for
  4883.                               lpCallerData is too large.
  4884.           
  4885.           WSAEINVAL           The parameter g specified in
  4886.                               the condition function is not
  4887.                               a valid value, or the
  4888.                               parameter s is a listening
  4889.                               socket.
  4890.           
  4891.           WSAEISCONN          The socket is already
  4892.                               connected.
  4893.           
  4894.           WSAEMFILE           No more socket descriptors are
  4895.                               available.
  4896.           
  4897.           WSAENETUNREACH      The network can't be reached
  4898.                               from this host at this time.
  4899.           
  4900.           WSAENOBUFS          No buffer space is available.
  4901.                               The socket cannot be
  4902.                               connected.
  4903.           
  4904.           WSAENOTSOCK         The descriptor is not a
  4905.                               socket.
  4906.           
  4907.           WSAEPROTONOSUPPORT  The lpCallerData augment is
  4908.                               not supported by the service
  4909.                               provider.
  4910.           
  4911.           WSAEWOULDBLOCK      The socket is marked as non-
  4912.                               blocking and the connection
  4913.                               cannot be completed
  4914.                               immediately.  It is possible
  4915.                               to PSselect() the socket while
  4916.                               it is connecting by
  4917.                               PSselect()ing it for writing.
  4918.  
  4919.  
  4920.           The following error codes may be returned by
  4921.           WSPEnumNetworkEvents() after the connect has
  4922.           completed.
  4923.  
  4924. WSANOTINITIALISED             A successful PSStartup() must
  4925.                               occur before using this SPI.
  4926.           
  4927.           WSAENETDOWN         The network subsystem has
  4928.                               failed.
  4929.           
  4930.           WSAEADDRINUSE       The specified address is
  4931.                               already in use.
  4932.           
  4933.           WSAEINTR            The (blocking) call was
  4934.                               canceled via
  4935.                               PSCancelBlockingCall().
  4936.           
  4937.           WSAEINPROGRESS      A blocking PII call is in
  4938.                               progress.
  4939.           
  4940.           WSAEADDRNOTAVAIL    The specified address is not
  4941.                               available from the local
  4942.                               machine.
  4943.           
  4944.           WSAEAFNOSUPPORT     Addresses in the specified
  4945.                               family cannot be used with
  4946.                               this socket.
  4947.           
  4948.           WSAECONNREFUSED     The attempt to connect was
  4949.                               forcefully rejected.
  4950.           
  4951.           WSAENETUNREACH      The network can't be reached
  4952.                               from this host at this time.
  4953.           
  4954.           WSAENOBUFS          No buffer space is available.
  4955.                               The socket cannot be
  4956.                               connected.
  4957.           
  4958.           WSAEOPNOTSUPP       The flow specs specified in
  4959.                               lpSFlowspec and lpGFlowspec
  4960.                               cannot be satisfied.
  4961.           
  4962.           WSAETIMEDOUT        Attempt to connect timed out
  4963.                               without establishing a
  4964.                               connection
  4965.  
  4966. See Also  WSPAccept(), WSPBindWSPbind(),
  4967.           WSPGetSockNameWSPgetsockname(),
  4968.           WSPGetSockOptWSPgetsockopt(), WSPsocket(),
  4969.           WSPSelectWSPselect(), WSPEventSelect(),
  4970.           WSPEnumNetworkEvents().
  4971. 3.1.2.17 WSPEnumNetworkEvents()
  4972.  
  4973. Description    Discover occurrences of network events for
  4974.           the indicated socket.
  4975.  
  4976.           #include <ws2spi.h>
  4977.  
  4978.           int WSPAPI WSPEnumNetworkEvents ( SOCKET s,
  4979.           WSAEVENT hEventObject, LPWSANETWORKEVENT
  4980.           lpNetworkEvents, LPINT lpiCount, int FAR * lpErrno
  4981.           );
  4982.  
  4983.           s          A descriptor identifying the socket.
  4984.           
  4985.           hEventObject   An optional handle identifying an
  4986.                     associated event object to be reset.
  4987.           
  4988.           lpNetworkEvents     An array of WSANETWORKEVENT
  4989.                     structs, each of which records an
  4990.                     occurred network event and the
  4991.                     associated error code.
  4992.           
  4993.           lpiCount  The number of elements in the array.
  4994.                     Upon returning, this parameter indicates
  4995.                     the actual number of elements in the
  4996.                     array, or the minimum number of elememts
  4997.                     needed to retrieve all the network
  4998.                     events if the return value is
  4999.                     WSAENOBUFS.
  5000.           
  5001.           lpErrno   A pointer to the error code.
  5002.  
  5003. Remarks   This function is used to discover which network
  5004.           events have occurred for the indicated socket
  5005.           since the last invocation of this function. It is
  5006.           intended for use in conjunction with
  5007.           WSPEventSelect(), which associates an event object
  5008.           with one or more network events. The socket's
  5009.           internal record of network events is copied to
  5010.           lpNetworkEvents, whereafter the internal network
  5011.           events record is cleared. If hEventObject is non-
  5012.           null, the indicated event object is also reset.
  5013.           The Winsock2 DLL guarantees that the operations of
  5014.           copying the network event record, clearing it and
  5015.           resetting any associated event object are atomic,
  5016.           such that the next occurrence of a nominated
  5017.           network event will cause the event object to
  5018.           become set.
  5019.           
  5020.           The following error codes may be returned along
  5021.           with the respective network event:
  5022.           Event: FD_CONNECT
  5023.           Error Code          Meaning
  5024.           WSAEADDRINUSE       The specified address is
  5025.                               already in use.
  5026.           
  5027.           WSAEADDRNOTAVAIL    The specified address is not
  5028.                               available from the local
  5029.                               machine.
  5030.           
  5031.           WSAEAFNOSUPPORT     Addresses in the specified
  5032.                               family cannot be used with
  5033.                               this socket.
  5034.           
  5035.           WSAECONNREFUSED     The attempt to connect was
  5036.                               forcefully rejected.
  5037.           
  5038.           WSAENETUNREACH      The network can't be reached
  5039.                               from this host at this time.
  5040.           
  5041.           WSAENOBUFS          No buffer space is available.
  5042.                               The socket cannot be
  5043.                               connected.
  5044.           
  5045.           WSAETIMEDOUT        Attempt to connect timed out
  5046.                               without establishing a
  5047.                               connection
  5048.  
  5049.           Event: FD_CLOSE
  5050.           Error Code          Meaning
  5051.           WSAENETDOWN         The network subsystem has
  5052.                               failed.
  5053.           
  5054.           WSAECONNRESET       The connection was reset by
  5055.                               the remote side.
  5056.           
  5057.           WSAECONNABORTED     The connection was aborted due
  5058.                               to timeout or other failure.
  5059.           
  5060.           Event: FD_READ
  5061.           Event: FD_WRITE
  5062.           Event: FD_OOB
  5063.           Event: FD_ACCEPT
  5064.           Event: FD_QOS
  5065.           Event: FD_GROUP_QOS
  5066.           Error Code          Meaning
  5067.           WSAENETDOWN         The network subsystem has
  5068.                               failed.
  5069.           
  5070. Return Value   The return value is 0 if the operation was
  5071.           successful. Otherwise the value SOCKET_ERROR is
  5072.           returned, and a specific error number is available
  5073.           in lpErrno.
  5074.  
  5075. Error Codes                   WSANOTINITIALISED   A
  5076.                               successful WSPStartup() must
  5077.                               occur before using this SPI.
  5078.           
  5079.           WSAENETDOWN         The network subsystem has
  5080.                               failed.
  5081.           
  5082.           WSAEINVAL           Indicates that one of the
  5083.                               specified parameters was
  5084.                               invalid
  5085.           
  5086.           WSAEINPROGRESS      A blocking Winsock call is in
  5087.                               progress, or the service
  5088.                               provider is still processing a
  5089.                               callback function (see section
  5090.                               ???).
  5091.  
  5092.           WSAENOBUFS          The supplied buffer is too
  5093.                               small.
  5094.           
  5095. See Also  WSPEventSelect()
  5096. 3.1.2.18 WSPEventSelect()
  5097.  
  5098. Description    Specify an event object to be associated with
  5099.           the supplied set of FD_XXX network events.
  5100.  
  5101.           #include <ws2spi.h>
  5102.  
  5103.           int WSPAPI WSPEventSelect ( SOCKET s, WSAEVENT
  5104.           hEventObject, long lNetworkEvents, int FAR *
  5105.           lpErrno );
  5106.  
  5107.           s          A descriptor identifying the socket.
  5108.           
  5109.           hEventObject   A handle identifying the event
  5110.                     object to be associated with the
  5111.                     supplied set of FD_XXX network events.
  5112.           
  5113.           lNetworkEvents A bitmask which specifies the
  5114.                     combination of FD_XXX network events in
  5115.                     which the application has interest.
  5116.           
  5117.           lpErrno   A pointer to the error code.
  5118.  
  5119. Remarks   This function is used to specify an event object,
  5120.           hEventObject, to be associated with the selected
  5121.           FD_XXX network events, lNetworkEvents. The socket
  5122.           for which an event object is specified is
  5123.           identified by s. The event object is set when any
  5124.           of the nominated network events occuroccurr.
  5125.  
  5126.           WSPEventSelect() operates very similarly to
  5127.           WSPAsyncSelect32(), the difference being in the
  5128.           actions taken when a nominated network event
  5129.           occurs. Whereas WSPAsyncSelect32() causes an
  5130.           application-specified Windows message to be
  5131.           posted, WSPEventSelect() sets the associated event
  5132.           object and records the occurrence of this event by
  5133.           setting the corresponding bit in an internal
  5134.           network event record. An application can use
  5135.           WSAWaitForMultipleEvents() or
  5136.           WSAGetOverlappedResult() to wait or poll on the
  5137.           event object, and use WSAEnumNetworkEvents() to
  5138.           retrieve the contents of the internal network
  5139.           event record and thus determine which of the
  5140.           nominated network events have occurred.
  5141.           
  5142.           This function automatically sets socket s to non-
  5143.           blocking mode, regardless of the value of
  5144.           lNetworkEvents. See WSPIoctlSocketWSPioctlsocket()
  5145.           about how to set the socket back to blocking mode.
  5146.           
  5147.                FD_ACCEPT Want to receive notification of
  5148.                          incoming connections
  5149.                FD_CONNECT     Want to receive notification
  5150.                          of completed connection
  5151.                FD_CLOSE  Want to receive notification of
  5152.                          socket closure
  5153.           The lNetworkEvents parameter is constructed by
  5154.           or'ing any of the values specified in the
  5155.           following list.
  5156.  
  5157.                Value      Meaning
  5158.                FD_READ    Want to receive notification of
  5159.                           readiness for reading
  5160.                FD_WRITE   Want to receive notification of
  5161.                           readiness for writing
  5162.                FD_OOB     Want to receive notification of
  5163.                           the arrival of out-of-band data
  5164.                FD_ACCEPT  Want to receive notification of
  5165.                           incoming connections
  5166.                FD_CONNECT Want to receive notification of
  5167.                           completed connection
  5168.                FD_CLOSE   Want to receive notification of
  5169.                           socket closure
  5170.                FD_QOS     Want to receive notification of
  5171.                           socket Quality of Service (QOS)
  5172.                           changes
  5173.                FD_GROUP_QOS    Want to receive notification
  5174.                           of socket group Quality of
  5175.                           Service (QOS) changes
  5176.                
  5177.  
  5178.           Issuing a WSPEventSelect() for a socket cancels
  5179.           any previous WSPAsyncSelect32() or
  5180.           WSPEventSelect() for the same socket and clears
  5181.           all bits in the internal network event record. For
  5182.           example, to associate an event object with both
  5183.           reading and writing network events, the
  5184.           application must call WSPEventSelect() with both
  5185.           FD_READ and FD_WRITE, as follows:
  5186.           
  5187.           rc = WSPEventSelect(s, hEventObject,
  5188.                     FD_READ|FD_WRITE);
  5189.           
  5190.           It is not possible to specify different event
  5191.           objects for different network events. The
  5192.           following code will not work; the second call will
  5193.           cancel the effects of the first, and only FD_WRITE
  5194.           network event will be associated with
  5195.           hEventObject2:
  5196.           
  5197.           rc = WSPEventSelect(s, hEventObject1, FD_READ);
  5198.           rc = WSPEventSelect(s, hEventObject2, FD_WRITE);
  5199.           
  5200.           To cancel the association and selection of network
  5201.           events on a socket, lNetworkEvents should be set
  5202.           to zero, in which case the hEventObject parameter
  5203.           will be ignored.
  5204.           
  5205.           rc = WSPEventSelect(s, hEventObject, 0);
  5206.           
  5207.           Closing a socket with
  5208.           WSPCloseSocketWSPclosesocket() also cancels the
  5209.           association and selection of network events
  5210.           specified in WSPEventSelect() for the socket. The
  5211.           application, however, still needs to call
  5212.           WSACloseEvent() to explicitly close the event
  5213.           object and free any resources.
  5214.           
  5215.           Since a WSAAccept()'ed socket has the same
  5216.           properties as the listening socket used to accept
  5217.           it, any WSPEventSelect() association and network
  5218.           events selection set for the listening socket
  5219.           apply to the accepted socket. For example, if a
  5220.           listening socket has WSPEventSelect() association
  5221.           of hEventOject with FD_ACCEPT, FD_READ, and
  5222.           FD_WRITE, then any socket accepted on that
  5223.           listening socket will also have FD_ACCEPT,
  5224.           FD_READ, and FD_WRITE network events associated
  5225.           with the same hEventObject. If a different
  5226.           hEventObject or network events are desired, the
  5227.           application should call WSPEventSelect(), passing
  5228.           the accepted socket and the desired new
  5229.           information.6
  5230.  
  5231. Return Value   The return value is 0 if the application's
  5232.           specification of the network events and the
  5233.           associated event object was successful. Otherwise
  5234.           the value SOCKET_ERROR is returned, and a specific
  5235.           error number is available in lpErrno.
  5236.  
  5237. Comments  The scenarios that an event object is signaled is
  5238.           dependent on the associated network events.  The
  5239.           scenarios for each network event are listed below:
  5240.  
  5241.           Event          Scenarios the associated event
  5242.                          object get signaled
  5243.           FD_READ        When data arrives in an emply
  5244.                          transport internal queue, or at the
  5245.                          end of the recv()/recvfrom() call
  5246.                          if there is more data to be read.
  5247.           FD_WRITE       When a socket is first connected
  5248.                          with connect() or accepted with
  5249.                          accept(), or after a send() or
  5250.                          sendto(), or WSAGetBuffer() fails
  5251.                          with WSAEWOULDBLOCK and buffer
  5252.                          space becomes available or
  5253.                          WSAGetBuffer()
  5254.           FD_OOB         The same as FD_READ, but with out-
  5255.                          of-band data.
  5256.           FD_ACCEPT      When an incoming connection request
  5257.                          arrives, or at the end of accept()
  5258.                          or WSAAcceptEx() (unless the error
  5259.                          code returned is WSATRY_AGAIN) if
  5260.                          there are more incoming connection
  5261.                          requests.
  5262.           FD_CONNECT     When the connect operation
  5263.                          completed.
  5264.           FD_CLOSE       When the remote side closes the
  5265.                          virtual circuit and the application
  5266.                          has read all bufferred data for the
  5267.                          socket.
  5268.           FD_QOS         When the socket QOS changes.
  5269.           FD_GROUP_QOS   When the group QOS changes.
  5270.           
  5271.           If an network event has already happened when the
  5272.           application calls WSAEventSelect(), then the
  5273.           associated event object get signaled as
  5274.           appropriate.
  5275.           
  5276.           As in the case of the WSPSelectWSPselect() and
  5277.           WSPAsyncSelect32() functions, WSPEventSelect()
  5278.           will frequently be used to determine when a data
  5279.           transfer operation (WSPSendWSPsend() or
  5280.           WSPRecvWSPrecv()) can be issued with the
  5281.           expectation of immediate success. Nevertheless, a
  5282.           robust application must be prepared for the
  5283.           possibility that the event object is set and it
  5284.           issues a Winsock call which returns WSAEWOULDBLOCK
  5285.           immediately. For example, the following sequence
  5286.           of operations is possible:
  5287.           
  5288.           (i)       data arrives on socket s; Winsock sets
  5289.                     the WSPEventSelect event object
  5290.           (ii)      application does some other processing
  5291.           (iii)     while processing, application issues an
  5292.           WSPIoctlSocketWSPioctlsocket(s,
  5293.                     FIONREAD...) and notices that there is
  5294.                     data ready to be read
  5295.           (iv)      application issues a
  5296.                     WSPRecvWSPrecv(s,...) to read the data
  5297.           (v)       application eventually waits on event
  5298.                     object specified in WSPEventSelect,
  5299.                     which returns immediately indicating
  5300.                     that data is ready to read
  5301.           (vi)      application issues
  5302.                     WSPRecvWSPrecv(s,...), which fails with
  5303.                     the error WSAEWOULDBLOCK.
  5304.           
  5305.           Other sequences are possible.
  5306.           
  5307.           Having successfully recorded the occurrence of the
  5308.           network event (by setting the corresponding bit in
  5309.           the internal network event record) and signaled
  5310.           the associated event object, no further actions
  5311.           are taken for that network event until the
  5312.           application makes the function call which
  5313.           implicitly reenables the setting of that network
  5314.           event and signaling of the associated event
  5315.           object.
  5316.  
  5317.           Network Event  Re-enabling function
  5318.           FD_READ        WSPRecvWSPrecv() or
  5319.                          WSPRecvFromWSPrecvfrom()
  5320.           FD_WRITE       WSPSendWSPsend() or
  5321.                          WSPSendToWSPsendto() or
  5322.                          WSAGetBuffer()
  5323.           FD_OOB         WSPRecvWSPrecv()
  5324.           FD_ACCEPT      WSPAccept() unless the error code
  5325.                          returned is WSATRY_AGAIN indicating
  5326.                          that the condition function
  5327.                          returned CF_DEFER
  5328.           FD_CONNECT     NONE
  5329.           FD_CLOSE       NONE
  5330.           FD_QOS         WSPGetSockOptWSPgetsockopt() with
  5331.                          option SO_FLOWSPEC
  5332.           FD_GROUP_QOS   WSPGetSockOptWSPgetsockopt() with
  5333.                          option SO_GROUP_FLOWSPEC
  5334.           
  5335.           Any call to the reenabling routine, even one which
  5336.           fails, results in reenabling of recording and
  5337.           setting for the relevant network event and event
  5338.           object, respectively.
  5339.           
  5340.           For FD_READ, FD_OOB, FD_ACCEPT, FD_QOS and
  5341.           FD_GROUP_QOS network events, network event
  5342.           recording and event object setting are "level-
  5343.           triggered." This means that if the reenabling
  5344.           routine is called and the relevant network
  5345.           condition is still valid after the call, the
  5346.           network event is recorded and the associated event
  5347.           object is set . This allows an application to be
  5348.           event-driven and not be concerned with the amount
  5349.           of data that arrives at any one time. Consider the
  5350.           following sequence:
  5351.           
  5352.           (i)       transport provider receives 100 bytes of
  5353.                     data on socket s and causes Winsock2 DLL
  5354.                     to record the FD_READ network event and
  5355.                     set the associated event object.
  5356.           (ii)      The application issues WSPRecvWSPrecv(
  5357.                     s, buffptr, 50, 0) to read 50 bytes.
  5358.           (iii)     The transport provider causes WINSOCK
  5359.                     DLL to record the FD_READ network event
  5360.                     and sets the associated event object
  5361.                     again since there is still data to be
  5362.                     read.
  5363.           
  5364.           With these semantics, an application need not read
  5365.           all available data in response to an FD_READ
  5366.           network event --a single WSPRecvWSPrecv() in
  5367.           response to each FD_READ network event is
  5368.           appropriate.  If an application issues multiple
  5369.           recv() calls in response to a single FD_READ, it
  5370.           may receive multiple FD_READ messages.  Such an
  5371.           application may wish to disable FD_READ messages
  5372.           before starting the recv() calls by calling
  5373.           WSAAsyncSelect() with the FD_READ event not set.
  5374.           
  5375.           If a network event has already happened when the
  5376.           application calls WSPEventSelect() or when the
  5377.           reenabling function is called, then a network
  5378.           event is recorded and the associated event object
  5379.           is set as appropriate. All the network events have
  5380.           persistence beyond the occurrence of their
  5381.           respective events. For example, consider the
  5382.           following sequence: 1) an application calls
  5383.           WSPListenWSPlisten(), 2) a connect request is
  5384.           received but not yet accepted, 3) the application
  5385.           calls WSPEventSelect() specifying that it is
  5386.           interested in the FD_ACCEPT network event for the
  5387.           socket. Due to the persistence of network events,
  5388.           Winsock records the FD_ACCEPT network event and
  5389.           sets the associated event object immediately.
  5390.           
  5391.           The FD_WRITE network event is handled slightly
  5392.           differently. An FD_WRITE network event is recorded
  5393.           when a socket is first connected with WSPConnect()
  5394.           or accepted with WSPAccept(), and then after a
  5395.           WSPSendWSPsend() or WSPSendToWSPsendto(), or
  5396.           WSAGetBuffer() fails with WSAEWOULDBLOCK and
  5397.           buffer space becomes available. Therefore, an
  5398.           application can assume that sends are possible
  5399.           starting from the first FD_WRITE network event
  5400.           settingsettting and lasting until a send returns
  5401.           WSAEWOULDBLOCK. After such a failure the
  5402.           application will find out that sends are again
  5403.           possible when an FD_WRITE network event is
  5404.           recorded  and the associated event object is set .
  5405.           
  5406.           The FD_OOB network event is used only when a
  5407.           socket is configured to receive out-of-band data
  5408.           separately. If the socket is configured to receive
  5409.           out-of-band data in-line, the out-of-band
  5410.           (expedited) data is treated as normal data and the
  5411.           application should register an interest in, and
  5412.           will get, FD_READ network event, not FD_OOB
  5413.           network event. An application may set or inspect
  5414.           the way in which out-of-band data is to be handled
  5415.           by using WSPSetSockOptWSPsetsockopt() or
  5416.           WSPGetSockOptWSPgetsockopt() for the SO_OOBINLINE
  5417.           option.
  5418.           
  5419.           The error code in an FD_CLOSE network event
  5420.           indicates whether the socket close was graceful or
  5421.           abortive. If the error code is 0, then the close
  5422.           was graceful; if the error code is WSAECONNRESET,
  5423.           then the socket's virtual circuit was reset. This
  5424.           only applies to connection-oriented sockets such
  5425.           as SOCK_STREAM.
  5426.           
  5427.           The FD_CLOSE network event is recorded when a
  5428.           close indication is received for the virtual
  5429.           circuit corresponding to the socket. In TCP terms,
  5430.           this means that the FD_CLOSE is recorded when the
  5431.           connection goes into the FIN WAIT or CLOSE WAIT
  5432.           states. This results from the remote end
  5433.           performing a WSPShutdownWSPshutdown() on the send
  5434.           side or a WSPCloseSocketWSPclosesocket().
  5435.           
  5436.           Please note Winsock will record ONLY an FD_CLOSE
  5437.           network event to indicate closure of a virtual
  5438.           circuit. It will NOT record an FD_READ network
  5439.           event to indicate this condition.
  5440.           
  5441.           The FD_QOS or FD_GROUP_QOS network event is
  5442.           recorded when any field in the flow spec
  5443.           associated with socket s or the socket group that
  5444.           s belongs to has changed, respectively.
  5445.           Applications should use
  5446.           WSPGetSockOptWSPgetsocketopt() with option
  5447.           SO_FLOWSPEC or SO_GROUP_FLOWSPEC to get the
  5448.           current QOS for socket s or for the socket group s
  5449.           belongs to, respectively.
  5450.           
  5451. Error Codes                   WSANOTINITIALISED   A
  5452.                               successful WSPStartup() must
  5453.                               occur before using this SPI.
  5454.           
  5455.           WSAENETDOWN         The network subsystem has
  5456.                               failed.
  5457.           
  5458.           WSAEINVAL           Indicates that one of the
  5459.                               specified parameters was
  5460.                               invalid, or the specified
  5461.                               socket is in an invalid state.
  5462.           
  5463.           WSAEINPROGRESS      A blocking Winsock call is in
  5464.                               progress, or the service
  5465.                               provider is still processing a
  5466.                               callback function (see section
  5467.                               ???).
  5468.           
  5469.           WSAENOTSOCK         The descriptor is not a
  5470.                               socket.
  5471.  
  5472.  
  5473. See Also  WSPEnumNetworkEvents()
  5474. 3.1.2.19 WSPIsBlocking32()
  5475.  
  5476. Description    Determine if a blocking call is in progress.
  5477.  
  5478.           #include <ws2spi.h>
  5479.  
  5480.           BOOL WSPAPI WSPIsBlocking32 ( VOID );
  5481.  
  5482. Remarks   This function is only applicable to the 32-bit
  5483. SPIis only available in the 32-bit SPI.
  5484.           
  5485.           This function allows the Winsock DLL to determine
  5486.           if it is executing while waiting for a previous
  5487.           blocking call to complete.
  5488.           
  5489. Return Value   The return value is TRUE if there is an
  5490.           outstanding blocking function awaiting completion.
  5491.           Otherwise, it is FALSE.
  5492.           On a blocking socket, the return value indicates
  5493.           success or failure of the connection attempt.
  5494.           
  5495.  
  5496. See Also  WSPCancelBlockingCall32(), WSPSetBlockingHook32(),
  5497.           WSPUnhookBlockingHook32()
  5498. 3.1.2.210 WSPRrecv()
  5499.  
  5500. Description    Receive data from a socket. {warning! Since
  5501.           both the recv() and WSARecv() API functions map to
  5502.           this function the description needs to be more
  5503.           generic with respect to overlapped I/O This also
  5504.           applies to WSPRecvFromWSPrecvFrom, WSPSendWSPSend,
  5505.           WSPSendToWSPSendTo}
  5506.  
  5507.           #include <ws2spi.h>
  5508.  
  5509.           int WSPAPI WSPRecvWSPrecv ( SOCKET s, LPVOID
  5510.           lpBuffer, DWORD nNumberOfBytesToRecv, LPDWORD
  5511.           lpNumberOfBytesRecvd, LPINT lpFlags,
  5512.           LPWSAOVERLAPPED lpOverlapped,
  5513.           LPWSAOVERLAPPED_COMPLETION_ROUTINE
  5514.           lpCompletionRoutine, int FAR * lpErrno );
  5515.  
  5516.           
  5517.           s               A descriptor identifying an
  5518.                          overlapped, connected socket. which
  5519.                          was created using WSPSocket() with
  5520.                          flag WSA_FLAG_OVERLAPPED.
  5521.           
  5522.           lpBuffer       A pointer to the buffer for the
  5523.                          incoming data.
  5524.           
  5525.           nNumberOfBytesToRecv     The number of bytes to
  5526.                          receive from the network.
  5527.           
  5528.           lpNumberOfBytesRecvd     A pointer to the number
  5529.                          of bytes received by this call.
  5530.           
  5531.           lpFlags        A pointer to flags.
  5532.           
  5533.           lpOverlapped   A pointer to a WSAOVERLAPPED
  5534.                          structure.
  5535.           
  5536.           lpCompletionRoutine A pointer to the completion
  5537.                          routine called when the receive
  5538.                          operation has been completed.
  5539.           
  5540.           lpErrno        A pointer to the error code.
  5541.  
  5542. Remarks   This function is used on a connection-oriented
  5543.           socket specified by s to post a buffer into which
  5544.           incoming data will be placed as it becomes
  5545.           available. It can also be used on connectionless
  5546.           sockets which have a stipulated default peer
  5547.           address established via the WSPConnect()
  5548.           functions.
  5549.           
  5550.           For non-overlapped socket, this function behaves
  5551.           like the standard recv() API with identical
  5552.           blocking semantics and the lpOverlapped and
  5553.           lpCompletionRoutine parameters are ignored. The
  5554.           completion status of this SPI is the final
  5555.           completion status of the receive operation.
  5556.           
  5557.           For overlapped sockets, the final completion
  5558.           status is retrieved via the
  5559.           WSAGetOverlappedResult() API.
  5560.  
  5561.           For byte stream style sockets (e.g., type
  5562.           SOCK_STREAM), incoming data is placed into the
  5563.           buffer until the buffer is filled. If the socket
  5564.           has been configured for in-line reception of out-
  5565.           of-band data (socket option SO_OOBINLINE) and out-
  5566.           of-band data is unread, only out-of-band data will
  5567.           be filled.  The application may use the
  5568.           ioctlsocket() SIOCATMARK to determine whether any
  5569.           more out-of-band data remains to be read.
  5570.           
  5571.           For message-oriented sockets (e.g., type
  5572.           SOCK_DGRAM), an incoming message is placed into
  5573.           the supplied buffer, up to the size of the buffer
  5574.           supplied. If the message is larger than the buffer
  5575.           supplied, the buffer is filled with the first part
  5576.           of the message, the excess data is lost, and
  5577.           WSPRecvWSPrecv() indicatesreturns the error
  5578.           WSAEMSGSIZE.
  5579.           
  5580.           If no incoming data is available at the socket,
  5581.           the recv() call waits for data to arrive unless
  5582.           the socket is non-blocking.  In this case a value
  5583.           of SOCKET_ERROR is returned with the error code
  5584.           set to WSAEWOULDBLOCK.  The select(),
  5585.           WSAAsyncSelect() or WSACallbackSelect() calls may
  5586.           be used to determine when more data arrives.
  5587.           
  5588.           If the socket is connection-oriented and the
  5589.           remote side has shut down the connection
  5590.           gracefully, WSPRecvWSPrecv() will complete
  5591.           immediately indicating zero bytes received. If the
  5592.           connection has been reset, a WSPRecvWSPrecv() will
  5593.           fail with the error WSAECONNRESET.
  5594.           
  5595.           This function may be called from within the
  5596.           completion routine of a previous WSPRecvWSPrecv(),
  5597.           WSPRecvFromWSPrecvfrom(), WSPSendWSPsend() or
  5598.           WSPSendToWSPsendto() function.
  5599.           
  5600.           When called with an overlapped socket, the
  5601.           lpOverlapped parameter much be valid for the
  5602.           duration of the overlapped operation. The
  5603.           WSAOVERLAPPED structure has the following form:
  5604.           
  5605.                typedef struct _WSAOVERLAPPED {
  5606.                     DWORD          Internal;      //
  5607.           reserved
  5608.                     DWORD          InternalHigh;  //
  5609.           reserved
  5610.                     DWORD          Offset;        // ignored
  5611.                     DWORD          OffsetHigh;         //
  5612.           ignored
  5613.                     WSAEVENT  hEvent;
  5614.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  5615.           
  5616.           If the lpCompletionRoutine parameter is NULL, the
  5617.           hEvent field of lpOverlapped must be an event
  5618.           object handle which is signaled when the
  5619.           overlapped operation completes. An application can
  5620.           use WSAWaitForMultipleEvents() or
  5621.           WSAGetOverlappedResult() to wait or poll on the
  5622.           event object.
  5623.           
  5624.           The lpCompletionRoutine must be non-NULL and the
  5625.           hEvent field is used to pass context information
  5626.           to the completion routine.
  5627.           
  5628.           The prototype of the completion routine is as
  5629.           follows:
  5630.           
  5631.                VOID CALLBACK CompletionRoutine( SOCKET s,
  5632.           DWORD dwError,      DWORD cbTransferred,
  5633.           LPWSAOVERLAPPED lpOverlapped );
  5634.           
  5635.           CompletionRoutine is a placeholder for an
  5636.           application-defined or library-defined function
  5637.           pointername. dwError specifies the completion
  5638.           status for the overlapped operation as indicated
  5639.           by lpOverlapped. cbTransferred specifies the
  5640.           number of bytes received. This function does not
  5641.           return a value.
  5642.           
  5643.           Returning from this function allows invocation of
  5644.           another pending completion routine for this
  5645.           socket. In Win32 environments, all waiting
  5646.           completion routines are called before the
  5647.           alterable thread's wait is satisfied with a return
  5648.           code of WSA_IO_COMPLETION. The completion routines
  5649.           may be called in any order, not necessarily in the
  5650.           same order the overlapped operations are
  5651.           completed. However, the posted buffers are
  5652.           guaranteed to be filled in the same order they are
  5653.           supplied
  5654.           
  5655.           lpFlags may be used to influence the behavior of
  5656.           the function invocation beyond the options
  5657.           specified for the associated socket.  That is, the
  5658.           semantics of this function are determined by the
  5659.           socket options and the lpFlags parameter.  The
  5660.           latter is constructed by or-ing any of the
  5661.           following values:
  5662.  
  5663.           Value     Meaning
  5664.           MSG_PEEK  Peek at the incoming data.  The data is
  5665.                     copied into the buffer but is not
  5666.                     removed from the input queue. {Hmmm,
  5667.                     "input queue" implies receive buffering
  5668.                     is occurring, which sort of defeats the
  5669.                     purpose of overlapped I/O.  Should this
  5670.                     be a valid flag for overlapped I/O?}
  5671.           
  5672.           MSG_OOB   Process out-of-band data (See section
  5673.                     for a discussion of this topic.)
  5674.           
  5675.           Upon the completion of the overlapped operation,
  5676.           the lpNumberOfBytesRecvd parameter is filled with
  5677.           the number of bytes received, and, for message-
  5678.           oriented sockets, the MSG_PARTIAL bit is set in
  5679.           the lpFlags parameter if a partial message is
  5680.           received. If a complete message is received,
  5681.           MSG_PARTIAL is cleared in lpFlags.
  5682.  
  5683.  
  5684. Return Value   If no error occurs, WSPRecvWSPrecv() returns
  5685.           the number of bytes received.  If the connection
  5686.           has been closed, it returns 0. Otherwise, a value
  5687.           of SOCKET_ERROR is returned, and a specific error
  5688.           code is available in lpErrno.
  5689.  
  5690. Error Codes                   WSANOTINITIALISED   A
  5691.                               successful WSPStartup() must
  5692.                               occur before using this SPI.
  5693.           
  5694.           WSAENETDOWN         The network subsystem has
  5695.                               failed.
  5696.           
  5697.           WSAENOTCONN         The socket is not connected.
  5698.           
  5699.           WSAEINTR            The (blocking) call was
  5700.                               canceled via
  5701.                               WSACancelBlockingCall().
  5702.           
  5703.           WSAEINPROGRESS      A blocking PII operation is in
  5704.                               progress.
  5705.  
  5706.           WSAENETRESET        The connection must be reset
  5707.                               because the service provider
  5708.                               dropped it.
  5709.           
  5710.           WSAENOTSOCK         The descriptor is not a
  5711.                               socket.
  5712.           
  5713.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  5714.                               socket is not stream style
  5715.                               such as type SOCK_STREAM, out-
  5716.                               of-band data is not supported
  5717.                               in the communication domain
  5718.                               associated with this socket,
  5719.                               or the socket is
  5720.                               unidirectional and supports
  5721.                               only send operations.
  5722.           
  5723.           WSAESHUTDOWN        The socket has been shutdown;
  5724.                               it is not possible to
  5725.                               WSPRecvWSPrecv() on a socket
  5726.                               after WSPShutdownWSPshutdown()
  5727.                               has been invoked with how set
  5728.                               to SD_RECEIVE or SD_BOTH.
  5729.           
  5730.           WSAEWOULDBLOCK      There are too many outstanding
  5731.                               overlapped I/O requests.
  5732.           
  5733.           WSAEMSGSIZE         The message was too large to
  5734.                               fit into the specified buffer
  5735.                               and was truncated. Any
  5736.                               trailing portion of the
  5737.                               message that did not fit into
  5738.                               the buffer has been discarded.
  5739.                                {Does this make sense?}
  5740.           
  5741.           WSAEINVAL           The socket has not been bound
  5742.                               with WSPBindWSPbind(), or the
  5743.                               socket is not created with the
  5744.                               overlapped flag.
  5745.           
  5746.           WSAECONNABORTED     The virtual circuit was
  5747.                               aborted due to timeout or
  5748.                               other failure.
  5749.           
  5750.           WSAECONNRESET       The virtual circuit was reset
  5751.                               by the remote side.
  5752.  
  5753. See Also  WSPSocket()
  5754. 3.1.2.121 WSPRecvFromWSPrecvfrom()
  5755.  
  5756. Description    Receive a datagram and store the source
  5757.           address.
  5758.  
  5759.           #include <ws2spi.h>
  5760.  
  5761.           int WSPAPI WSPRecvFromWSPrecvfrom ( SOCKET s,
  5762.           LPVOID lpBuffer, DWORD nNumberOfBytesToRecv,
  5763.           LPDWORD lpNumberOfBytesRecvd, LPINT lpFlags,
  5764.           LPVOID lpFrom, LPINT lpFromlen, LPWSAOVERLAPPED
  5765.           lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE
  5766.           lpCompletionRoutine, int FAR * lpErrno );
  5767.  
  5768.           
  5769.           s               A descriptor identifying an
  5770.                          overlapped, connected socket. which
  5771.                          was created using WSPSocket() with
  5772.                          flag WSA_FLAG_OVERLAPPED.
  5773.           
  5774.           lpBuffer       A pointer to the buffer for the
  5775.                          incoming data.
  5776.           
  5777.           nNumberOfBytesToRecv     The number of bytes to
  5778.                          receive from the network.
  5779.           
  5780.           lpNumberOfBytesRecvd     A pointer to the number
  5781.                          of bytes received by this call.
  5782.           
  5783.           lpFlags        A pointer to flags.
  5784.           
  5785.           lpFrom         An optional pointer to a buffer
  5786.                          which will hold the source address
  5787.                          upon the completion of the
  5788.                          overlapped operation.
  5789.           
  5790.           lpFromlen      An optional pointer to the size of
  5791.                          the from buffer.
  5792.           
  5793.           lpOverlapped   A pointer to a WSAOVERLAPPED
  5794.                          structure.
  5795.           
  5796.           lpCompletionRoutine A pointer to the completion
  5797.                          routine called when the receive
  5798.                          operation has been completed.
  5799.           
  5800.           lpErrno        A pointer to the error code.
  5801.  
  5802. Remarks   This function is used to post a buffer into which
  5803.           incoming data will be placed as it becomes
  5804.           available on a (possibly connected) socket. For
  5805.           connectionless socket types, the address from
  5806.           which the data originated is copied to the buffer
  5807.           pointed by lpFrom. The value pointed to by
  5808.           lpFromlen is initialized to the size of this
  5809.           buffer, and is modified on return to indicate the
  5810.           actual size of the address stored there. The
  5811.           lpFrom and lpFromlen parameters are ignored for
  5812.           connection-oriented sockets.
  5813.  
  5814.           For non-overlapped socket, this function behaves
  5815.           like the standard recvfrom() API with identical
  5816.           blocking semantics. The lpOverlapped and
  5817.           lpCompletionRoutine parameters are ignored. The
  5818.           completion status of this SPI is the final
  5819.           completion status of the receive operation.
  5820.           
  5821.           For overlapped sockets, the final completion
  5822.           status is retrieved via the
  5823.           WSAGetOverlappedResult() API.
  5824.  
  5825.           For byte stream style sockets (e.g., type
  5826.           SOCK_STREAM), incoming data is placed into the
  5827.           buffer until the buffer is filled. For message-
  5828.           oriented sockets, an incoming message is placed
  5829.           into the supplied buffer, up to the size of the
  5830.           buffer supplied. If the message is larger than the
  5831.           buffer supplied, the buffer is filled with the
  5832.           first part of the message, the excess data is
  5833.           lost, and WSPRecvFromWSPrecvfrom()
  5834.           indicatesreturns the error code WSAEMSGSIZE.
  5835.           
  5836.           If no incoming data is available at the socket,
  5837.           the recvfrom() call waits for data to arrive
  5838.           unless the socket is non-blocking.  In this case a
  5839.           value of SOCKET_ERROR is returned with the error
  5840.           code set to WSAEWOULDBLOCK.  The select(),
  5841.           WSAAsyncSelect() or WSACallbackSelect() may be
  5842.           used to determine when more data arrives.
  5843.           
  5844.           If the socket is connection-oriented and the
  5845.           remote side has shut down the connection
  5846.           gracefully, a WSPRecvFromWSPrecvfrom() will
  5847.           complete immediately with 0 bytes received. If the
  5848.           connection has been reset WSPRecvFromWSPrecvfrom()
  5849.           will fail with the error WSAECONNRESET.
  5850.           
  5851.           This function may be called from within the
  5852.           completion routine of a previous WSPRecvWSPrecv(),
  5853.           WSPRecvFromWSPrecvfrom(), WSPSendWSPsend() or
  5854.           WSPSendToWSPsendto() function.
  5855.           
  5856.           When called with an overlapped socket, the
  5857.           lpOverlapped parameter much be valid for the
  5858.           duration of the overlapped operation. The
  5859.           WSAOVERLAPPED structure has the following form:
  5860.           
  5861.                typedef struct _WSAOVERLAPPED {
  5862.                     DWORD          Internal;      //
  5863.           reserved
  5864.                     DWORD          InternalHigh;  //
  5865.           reserved
  5866.                     DWORD          Offset;        // ignored
  5867.                     DWORD          OffsetHigh;         //
  5868.           ignored
  5869.                     WSAEVENT  hEvent;
  5870.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  5871.           
  5872.           If the lpCompletionRoutine parameter is NULL, the
  5873.           hEvent field of lpOverlapped must be an event
  5874.           object handle which is signaled when the
  5875.           overlapped operation completes. An application can
  5876.           use WSAWaitForMultipleEvents() or
  5877.           WSAGetOverlappedResult() to wait or poll on the
  5878.           event object.
  5879.           
  5880.           The lpCompletionRoutine must be non-NULL and the
  5881.           hEvent field is used to pass context information
  5882.           to the completion routine.
  5883.           
  5884.           The prototype of the completion routine is as
  5885.           follows:
  5886.           
  5887.                VOID CALLBACK CompletionRoutine( SOCKET s,
  5888.           DWORD dwError,      DWORD cbTransferred,
  5889.           LPWSAOVERLAPPED lpOverlapped );
  5890.           
  5891.           CompletionRoutine is a placeholder for an
  5892.           application-defined or library-defined function
  5893.           pointername. dwError specifies the completion
  5894.           status for the overlapped operation as indicated
  5895.           by lpOverlapped. cbTransferred specifies the
  5896.           number of bytes received. This function does not
  5897.           return a value.
  5898.           
  5899.           Returning from this function allows invocation of
  5900.           another pending completion routine for this
  5901.           socket. In Win32 environments, all waiting
  5902.           completion routines are called before the
  5903.           alterable thread's wait is satisfied with a return
  5904.           code of WSA_IO_COMPLETION. The completion routines
  5905.           may be called in any order, not necessarily in the
  5906.           same order the overlapped operations are
  5907.           completed. However, the posted buffers are
  5908.           guaranteed to be filled in the same order they are
  5909.           supplied
  5910.           
  5911.           Flags may be used to influence the behavior of the
  5912.           function invocation beyond the options specified
  5913.           for the associated socket.  That is, the semantics
  5914.           of this function are determined by the socket
  5915.           options and the flags parameter.  The latter is
  5916.           constructed by or-ing any of the following values:
  5917.  
  5918.           Value     Meaning
  5919.           MSG_PEEK  Peek at the incoming data.  The data is
  5920.                     copied into the buffer but is not
  5921.                     removed from the input queue.
  5922.           
  5923.           MSG_OOB   Process out-of-band data (See section
  5924.                     for a discussion of this topic.)
  5925.           
  5926.           Upon the completion of the overlapped operation,
  5927.           the lpNumberOfBytesRecvd parameter is filled with
  5928.           the number of bytes received, and, for message-
  5929.           oriented sockets, the MSG_PARTIAL bit is set in
  5930.           the lpFlags parameter if a partial message is
  5931.           received. If a complete message is received,
  5932.           MSG_PARTIAL is cleared in lpFlags.
  5933.           
  5934.  
  5935. Return Value   If no error occurs, WSPRecvFromWSPrecvfrom()
  5936.           returns the number of bytes received.  If the
  5937.           connection has been closed, it returns0.
  5938.           Otherwise, a value of SOCKET_ERROR is returned,
  5939.           and a specific error code is available in lpErrno.
  5940.  
  5941. Error Codes                   WSANOTINITIALISED   A
  5942.                               successful WSPStartup() must
  5943.                               occur before using this SPI.
  5944.           
  5945.           WSAENETDOWN         The network subsystem has
  5946.                               failed.
  5947.           
  5948.           WSAEFAULT           The lpFromlen argument was
  5949.                               invalid: the lpFrom buffer was
  5950.                               too small to accommodate the
  5951.                               peer address.
  5952.           
  5953.           WSAEINTR            The (blocking) call was
  5954.                               canceled via
  5955.                               WSACancelBlockingCall().
  5956.           
  5957.           WSAEINPROGRESS      A blocking PII operation is in
  5958.                               progress.
  5959.  
  5960.           WSAEINVAL           The socket has not been bound
  5961.                               with WSPBindWSPbind(), or the
  5962.                               socket is not created with the
  5963.                               overlapped flag.
  5964.           
  5965.           WSAENETRESET        The connection must be reset
  5966.                               because the Winsock provider
  5967.                               dropped it.
  5968.           
  5969.           WSAENOTCONN         The socket is not connected
  5970.                               (connection-oriented sockets
  5971.                               only).
  5972.           
  5973.           WSAENOTSOCK         The descriptor is not a
  5974.                               socket.
  5975.           
  5976.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  5977.                               socket is not stream style
  5978.                               such as type SOCK_STREAM, out-
  5979.                               of-band data is not supported
  5980.                               in the communication domain
  5981.                               associated with this socket,
  5982.                               or the socket is
  5983.                               unidirectional and supports
  5984.                               only send operations.
  5985.           
  5986.           WSAESHUTDOWN        The socket has been shutdown;
  5987.                               it is not possible to
  5988.                               WSPRecvFromWSPrecvfrom() on a
  5989.                               socket after shutdown() has
  5990.                               been invoked with how set to
  5991.                               SD_RECEIVE or SD_BOTH.
  5992.           
  5993.           WSAEWOULDBLOCK      There are too many outstanding
  5994.                               overlapped I/O requests.
  5995.           
  5996.           WSAEMSGSIZE         The message was too large to
  5997.                               fit into the specified buffer
  5998.                               and was truncated. Any
  5999.                               trailing portion of the
  6000.                               message that did not fit into
  6001.                               the buffer has been discarded.
  6002.                               {Does this make sense?}
  6003.           
  6004.           WSAECONNABORTED     The virtual circuit was
  6005.                               aborted due to timeout or
  6006.                               other failure.
  6007.           
  6008.           WSAECONNRESET       The virtual circuit was reset
  6009.                               by the remote side.
  6010.           
  6011.           
  6012. See Also  WSPSocket()
  6013.  
  6014. W3.1.2.212 WSPSendWSPsend()
  6015.  
  6016. Description    Send data on a connected socket.
  6017.  
  6018.           #include <ws2spi.h>
  6019.  
  6020.           int WSPAPI WSPSendWSPsend ( SOCKET s, LPVOID
  6021.           lpBuffer, DWORD nNumberOfBytesToSend, LPDWORD
  6022.           lpNumberOfBytesSent, int nFlags, LPWSAOVERLAPPED
  6023.           lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE
  6024.           lpCompletionRoutine, int FAR * lpErrno );
  6025.  
  6026.           
  6027.           s               A descriptor identifying an
  6028.                          overlapped, connected socket. which
  6029.                          was created using WSPSocket() with
  6030.                          flag WSA_FLAG_OVERLAPPED.
  6031.           
  6032.           lpBuffer       A pointer to the buffer for the
  6033.                          outgoing data.
  6034.           
  6035.           nNumberOfBytesToSend     The number of bytes to
  6036.                          send to the network.
  6037.           
  6038.           lpNumberOfBytesSent A pointer to the number of
  6039.                          bytes sent by this call.
  6040.           
  6041.           iFlags         Flags.
  6042.           
  6043.           lpOverlapped   A pointer to a WSAOVERLAPPED
  6044.                          structure.
  6045.           
  6046.           lpCompletionRoutine A pointer to the completion
  6047.                          routine called when the send
  6048.                          operation has been completed.
  6049.           
  6050.           lpErrno        A pointer to the error code.
  6051.  
  6052. Remarks   WSPSendWSPsend() is used to write outgoing data on
  6053.           an overlapped, connected socket asynchronously.
  6054.           For message-oriented sockets, it is an error care
  6055.           must be taken not to exceed the maximum packet
  6056.           size of the underlying transportprovider, which
  6057.           can be obtained by getting the value of socket
  6058.           option SO_MAX_DG_SIZE. If the data is too long to
  6059.           pass atomically through the underlying protocol
  6060.           the error WSAEMSGSIZE is returned, and no data is
  6061.           transmitted.
  6062.  
  6063.           Note that the successful completion of a
  6064.           WSPSendWSPsend() does not indicate that the data
  6065.           was successfully delivered.
  6066.           
  6067.           For non-overlapped socket, this function behaves
  6068.           like the standard send() API with identical
  6069.           blocking semantics. The lpOverlapped and
  6070.           lpCompletionRoutine parameters are ignored. The
  6071.           completion status of this SPI is the final
  6072.           completion status of the receive operation.
  6073.           
  6074.           For overlapped sockets, the final completion
  6075.           status is retrieved via the
  6076.           WSAGetOverlappedResult() API.
  6077.  
  6078.           If no buffer space is available within the
  6079.           transport system to hold the data to be
  6080.           transmitted, send() will block unless the socket
  6081.           has been placed in a non-blocking I/O mode.  On
  6082.           non-blocking stream-oriented sockets, the number
  6083.           of bytes written may be between 1 and the
  6084.           requested length, depending on buffer availability
  6085.           on both the local and foreign hosts.  The
  6086.           select(), WSAAsyncSelect() or WSACallbackSelect()
  6087.           call may be used to determine when it is possible
  6088.           to send more data.
  6089.           
  6090.           This function may be called from within the
  6091.           completion routine of a previous WSPRecvWSPrecv(),
  6092.           WSPRecvFromWSPrecvfrom(), WSPSendWSPsend() or
  6093.           WSPSendToWSPsendto() function.
  6094.           
  6095.           When called with an overlapped socket, the
  6096.           lpOverlapped parameter much be valid for the
  6097.           duration of the overlapped operation. The
  6098.           WSAOVERLAPPED structure has the following form:
  6099.           
  6100.                typedef struct _WSAOVERLAPPED {
  6101.                     DWORD          Internal;      //
  6102.           reserved
  6103.                     DWORD          InternalHigh;  //
  6104.           reserved
  6105.                     DWORD          Offset;        // ignored
  6106.                     DWORD          OffsetHigh;         //
  6107.           ignored
  6108.                     WSAEVENT  hEvent;
  6109.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  6110.           
  6111.           If the lpCompletionRoutine parameter is NULL, the
  6112.           hEvent field of lpOverlapped must be an event
  6113.           object handle which is signaled when the
  6114.           overlapped operation completes. An application can
  6115.           use WSAWaitForMultipleEvents() or
  6116.           WSAGetOverlappedResult() to wait or poll on the
  6117.           event object.
  6118.           
  6119.           The lpCompletionRoutine must be non-NULL and the
  6120.           hEvent field is used to pass context information
  6121.           to the completion routine.
  6122.           
  6123.           The prototype of the completion routine is as
  6124.           follows:
  6125.           
  6126.                VOID CALLBACK CompletionRoutine( SOCKET s,
  6127.           DWORD dwError,      DWORD cbTransferred,
  6128.           LPWSAOVERLAPPED lpOverlapped );
  6129.           
  6130.           CompletionRoutine is a placeholder for an
  6131.           application-defined or library-defined function
  6132.           pointername. dwError specifies the completion
  6133.           status for the overlapped operation as indicated
  6134.           by lpOverlapped. cbTransferred specifies the
  6135.           number of bytes received. This function does not
  6136.           return a value.
  6137.           
  6138.           Returning from this function allows invocation of
  6139.           another pending completion routine for this
  6140.           socket. In Win32 environments, all waiting
  6141.           completion routines are called before the
  6142.           alterable thread's wait is satisfied with a return
  6143.           code of WSA_IO_COMPLETION. The completion routines
  6144.           may be called in any order, not necessarily in the
  6145.           same order the overlapped operations are
  6146.           completed. However, the posted buffers are
  6147.           guaranteed to be sent in the same order they are
  6148.           supplied
  6149.           
  6150.           Flags may be used to influence the behavior of the
  6151.           function invocation beyond the options specified
  6152.           for the associated socket. That is, the semantics
  6153.           of this function are determined by the socket
  6154.           options and the flags parameter. The latter is
  6155.           constructed by or-ing any of the following values:
  6156.  
  6157.           Value     Meaning
  6158.           MSG_DONTROUTE
  6159.                     Specifies that the data should not be
  6160.                     subject to routing. A Winsock service
  6161.                     provider may choose to ignore this flag;
  6162.                     see also the discussion of the
  6163.                     SO_DONTROUTE option in section
  6164.                     2.8.42.8.42.8.4.
  6165.           
  6166.           MSG_OOB   Send out-of-band data (stream style
  6167.                     socket such as SOCK_STREAM only; see
  6168.                     also section)
  6169.           
  6170.           MSG_PARTIAL    Specifies that lpBuffer only
  6171.                     contains a partial message. Note that
  6172.                     this flag will be ignored by transports
  6173.                     which do not support partial message
  6174.                     transmissions.
  6175.           
  6176.           Upon the completion of the overlapped operation,
  6177.           the lpNumberOfBytesSent parameter is filled with
  6178.           the number of bytes sent.
  6179.           
  6180.           MSG_INTERRUPT
  6181.                     Specifies that this function is being
  6182.                     called in interrupt context.
  6183.           
  6184.  
  6185. Return Value   If no error occurs, WSPSendWSPsend() returns
  6186.           0. the total number of characters sent.  (Note
  6187.           that this may be less than the number indicated by
  6188.           len.) Otherwise, a value of SOCKET_ERROR is
  6189.           returned, and a specific error code is available
  6190.           in lpErrno.
  6191.  
  6192. Error Codes                   WSANOTINITIALISED   A
  6193.                               successful WSPStartup() must
  6194.                               occur before using this SPI.
  6195.           
  6196.           WSAENETDOWN         The network subsystem has
  6197.                               failed.
  6198.           
  6199.           WSAEACCES           The requested address is a
  6200.                               broadcast address, but the
  6201.                               appropriate flag was not set.
  6202.           
  6203.           WSAEINTR            The (blocking) call was
  6204.                               canceled via
  6205.                               WSACancelBlockingCall().
  6206.           
  6207.           WSAEINPROGRESS      A blocking PII operation is in
  6208.                               progress.
  6209.           
  6210.           WSAEFAULT           The lpBuffer argument is not
  6211.                               in a valid part of the user
  6212.                               address space.
  6213.           
  6214.           WSAENETRESET        The connection must be reset
  6215.                               because the Winsock provider
  6216.                               dropped it.
  6217.           
  6218.           WSAENOBUFS          The Winsock provider reports a
  6219.                               buffer deadlock.
  6220.           
  6221.           WSAENOTCONN         The socket is not connected.
  6222.           
  6223.           WSAENOTSOCK         The descriptor is not a
  6224.                               socket.
  6225.           
  6226.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  6227.                               socket is not stream style
  6228.                               such as type SOCK_STREAM, out-
  6229.                               of-band data is not supported
  6230.                               in the communication domain
  6231.                               associated with this socket,
  6232.                               or the socket is
  6233.                               unidirectional and supports
  6234.                               only receive operations.
  6235.           
  6236.           WSAESHUTDOWN        The socket has been shutdown;
  6237.                               it is not possible to
  6238.                               WSPSendWSPsend() on a socket
  6239.                               after WSPShutdownWSPshutdown()
  6240.                               has been invoked with how set
  6241.                               to SD_SEND or SD_BOTH.
  6242.           
  6243.           WSAEWOULDBLOCK      There are too many outstanding
  6244.                               overlapped I/O requests.
  6245.           
  6246.           WSAEMSGSIZE         The socket is message-
  6247.                               oriented, and the message is
  6248.                               larger than the maximum
  6249.                               supported by the underlying
  6250.                               transport.
  6251.           
  6252.           WSAEINVAL           The socket has not been bound
  6253.                               with WSPBindWSPbind(), or the
  6254.                               socket is not created with the
  6255.                               overlapped flag.
  6256.           
  6257.           WSAECONNABORTED     The virtual circuit was
  6258.                               aborted due to timeout or
  6259.                               other failure.
  6260.           
  6261.           WSAECONNRESET       The virtual circuit was reset
  6262.                               by the remote side.
  6263.           
  6264.  
  6265. See Also  WSPSocket()
  6266.  
  6267. 3.1.2.213 WSPSendToWSPsendto()
  6268.  
  6269. Description    Send data to a specific destination using
  6270.           overlapped I/O.
  6271.  
  6272.           #include <ws2spi.h>
  6273.  
  6274.           int WSPAPI WSPSendToWSPsendto ( SOCKET s, LPVOID
  6275.           lpBuffer, DWORD nNumberOfBytesToSend, LPDWORD
  6276.           lpNumberOfBytesSent, int nFlags, LPVOID lpTo, int
  6277.           nTolen, LPWSAOVERLAPPED lpOverlapped,
  6278.           LPWSAOVERLAPPED_COMPLETION_ROUTINE
  6279.           lpCompletionRoutine, int FAR * lpErrno );
  6280.  
  6281.           
  6282.           s               A descriptor identifying an
  6283.                          overlapped, connected socket which
  6284.                          was created using WSPSocket() with
  6285.                          flag WSA_FLAG_OVERLAPPED.
  6286.           
  6287.           lpBuffer       A pointer to the buffer for the
  6288.                          outgoing data.
  6289.           
  6290.           nNumberOfBytesToSend     The number of bytes to
  6291.                          send to the network.
  6292.           
  6293.           lpNumberOfBytesSent A pointer to the number of
  6294.                          bytes sent by this call.
  6295.           
  6296.           iFlags         Flags.
  6297.           
  6298.           lpTo           An optional pointer to the address
  6299.                          of the target socket.
  6300.           
  6301.           iTolen         The size of the address in lpTo.
  6302.           
  6303.           lpOverlapped   A pointer to a WSAOVERLAPPED
  6304.                          structure.
  6305.           
  6306.           lpCompletionRoutine A pointer to the completion
  6307.                          routine called when the send
  6308.                          operation has been completed.
  6309.           
  6310.           lpErrno        A pointer to the error code.
  6311.  
  6312. Remarks   WSPSendToWSPsendto() is used to write outgoing
  6313.           data on an overlapped socket asynchronously. For
  6314.           message-oriented sockets, it is an errorcare must
  6315.           be taken not to exceed the maximum packet size of
  6316.           the underlying transportsubnets, which can be
  6317.           obtained by getting the value of socket option
  6318.           SO_MAX_DG_SIZE. If the data is too long to pass
  6319.           atomically through the underlying protocol the
  6320.           error WSAEMSGSIZE is returned, and no data is
  6321.           transmitted.
  6322.  
  6323.           Note that the successful completion of a
  6324.           WSPSendToWSPsendto() does not indicate that the
  6325.           data was successfully delivered.
  6326.           
  6327.           For non-overlapped socket, this function behaves
  6328.           like the standard sendto() API with identical
  6329.           blocking semantics. The lpOverlapped and
  6330.           lpCompletionRoutine parameters are ignored. The
  6331.           completion status of this SPI is the final
  6332.           completion status of the receive operation.
  6333.           
  6334.           For overlapped sockets, the final completion
  6335.           status is retrieved via the
  6336.           WSAGetOverlappedResult() API.
  6337.  
  6338.           WSPSendToWSPsendto() is normally used on a
  6339.           connectionless socket to send a datagram to a
  6340.           specific peer socket identified by the lpTo
  6341.           parameter. On a connection-oriented socket, the
  6342.           lpTo and iTolen parameters are ignored; in this
  6343.           case the WSPSendToWSPsendto() is equivalent to
  6344.           WSPSendWSPsend().
  6345.           
  6346.           This function may be called from within the
  6347.           completion routine of a previous WSPRecvWSPrecv(),
  6348.           WSPRecvFromWSPrecvfrom(), WSPSendWSPsend() or
  6349.           WSPSendToWSPsendto() function.
  6350.           
  6351.           When called with an overlapped socket, the
  6352.           lpOverlapped parameter much be valid for the
  6353.           duration of the overlapped operation. The
  6354.           WSAOVERLAPPED structure has the following form:
  6355.           
  6356.                typedef struct _WSAOVERLAPPED {
  6357.                     DWORD          Internal;      //
  6358.           reserved
  6359.                     DWORD          InternalHigh;  //
  6360.           reserved
  6361.                     DWORD          Offset;        // ignored
  6362.                     DWORD          OffsetHigh;         //
  6363.           ignored
  6364.                     WSAEVENT  hEvent;
  6365.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  6366.           
  6367.           If the lpCompletionRoutine parameter is NULL, the
  6368.           hEvent field of lpOverlapped must be an event
  6369.           object handle which is signaled when the
  6370.           overlapped operation completes. An application can
  6371.           use WSAWaitForMultipleEvents() or
  6372.           WSAGetOverlappedResult() to wait or poll on the
  6373.           event object.
  6374.           
  6375.           The lpCompletionRoutine must be non-NULL and the
  6376.           hEvent field is used to pass context information
  6377.           to the completion routine.
  6378.           
  6379.           The prototype of the completion routine is as
  6380.           follows:
  6381.           
  6382.                VOID CALLBACK CompletionRoutine( SOCKET s,
  6383.           DWORD dwError,      DWORD cbTransferred,
  6384.           LPWSAOVERLAPPED lpOverlapped );
  6385.           
  6386.           CompletionRoutine is a placeholder for an
  6387.           application-defined or library-defined function
  6388.           pointername. dwError specifies the completion
  6389.           status for the overlapped operation as indicated
  6390.           by lpOverlapped. cbTransferred specifies the
  6391.           number of bytes received. This function does not
  6392.           return a value.
  6393.           
  6394.           Returning from this function allows invocation of
  6395.           another pending completion routine for this
  6396.           socket. In Win32 environments, all waiting
  6397.           completion routines are called before the
  6398.           alterable thread's wait is satisfied with a return
  6399.           code of WSA_IO_COMPLETION. The completion routines
  6400.           may be called in any order, not necessarily in the
  6401.           same order the overlapped operations are
  6402.           completed. However, the posted buffers are
  6403.           guaranteed to be sent in the same order they are
  6404.           supplied
  6405.           
  6406.           Flags may be used to influence the behavior of the
  6407.           function invocation beyond the options specified
  6408.           for the associated socket. That is, the semantics
  6409.           of this function are determined by the socket
  6410.           options and the flags parameter. The latter is
  6411.           constructed by or-ing any of the following values:
  6412.  
  6413.           Value     Meaning
  6414.           MSG_DONTROUTE
  6415.                     Specifies that the data should not be
  6416.                     subject to routing. A WINSOCK service
  6417.                     provider may choose to ignore this flag;
  6418.                     see also the discussion of the
  6419.                     SO_DONTROUTE option in section
  6420.                     2.8.42.8.42.8.4.
  6421.           
  6422.           MSG_OOB   Send out-of-band data (stream style
  6423.                     socket such as SOCK_STREAM only; see
  6424.                     also section)
  6425.           
  6426.           MSG_PARTIAL    Specifies that lpBuffer only
  6427.                     contains a partial message. Note that
  6428.                     this flag will be ignored by transports
  6429.                     which do not support partial message
  6430.                     transmissions.
  6431.           
  6432.           Upon the completion of the overlapped operation,
  6433.           the lpNumberOfBytesSent parameter is filled with
  6434.           the number of bytes sent.
  6435.           
  6436.  
  6437. Return Value   If no error occurs, WSPSendToWSPsendto()
  6438.           returns 0. Otherwise, a value of SOCKET_ERROR is
  6439.           returned, and a specific error code is available
  6440.           in lpErrno.
  6441.  
  6442. Error Codes                   WSANOTINITIALISED   A
  6443.                               successful WSPStartup() must
  6444.                               occur before using this SPI.
  6445.           
  6446.           WSAENETDOWN         The network subsystem has
  6447.                               failed.
  6448.           
  6449.           WSAEACCES           The requested address is a
  6450.                               broadcast address, but the
  6451.                               appropriate flag was not set.
  6452.           
  6453.           WSAEINTR            The (blocking) call was
  6454.                               canceled via
  6455.                               WSACancelBlockingCall().
  6456.           
  6457.           WSAEINPROGRESS      A blocking PII operation is in
  6458.                               progress.
  6459.  
  6460.           WSAEFAULT           The lpBuffer or lpTo
  6461.                               parameters are not part of the
  6462.                               user address space, or the
  6463.                               lpTo argument is too small
  6464.                               (less than the sizeof a struct
  6465.                               sockaddr).
  6466.           
  6467.           WSAENETRESET        The connection must be reset
  6468.                               because the Winsock provider
  6469.                               dropped it.
  6470.           
  6471.           WSAENOBUFS          The Winsock provider reports a
  6472.                               buffer deadlock.
  6473.           
  6474.           WSAENOTCONN         The socket is not connected
  6475.                               (connection-oriented sockets
  6476.                               only)
  6477.           
  6478.           WSAENOTSOCK         The descriptor is not a
  6479.                               socket.
  6480.           
  6481.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  6482.                               socket is not stream style
  6483.                               such as type SOCK_STREAM, out-
  6484.                               of-band data is not supported
  6485.                               in the communication domain
  6486.                               associated with this socket,
  6487.                               or the socket is
  6488.                               unidirectional and supports
  6489.                               only receive operations.
  6490.           
  6491.           WSAESHUTDOWN        The socket has been shutdown;
  6492.                               it is not possible to
  6493.                               WSPSendToWSPsendto() on a
  6494.                               socket after
  6495.                               WSPShutdownWSPshutdown() has
  6496.                               been invoked with how set to
  6497.                               SD_SEND or SD_BOTH.
  6498.           
  6499.           WSAEWOULDBLOCK      There are too many outstanding
  6500.                               overlapped I/O requests.
  6501.           
  6502.           WSAEMSGSIZE         The socket is message-
  6503.                               oriented, and the message is
  6504.                               larger than the maximum
  6505.                               supported by the underlying
  6506.                               transport.
  6507.           
  6508.           WSAEINVAL           The socket has not been bound
  6509.                               with WSPBindWSPbind(), or the
  6510.                               socket is not created with the
  6511.                               overlapped flag.
  6512.           
  6513.           WSAECONNABORTED     The virtual circuit was
  6514.                               aborted due to timeout or
  6515.                               other failure.
  6516.           
  6517.           WSAECONNRESET       The virtual circuit was reset
  6518.                               by the remote side.
  6519.           
  6520.           WSAEADDRNOTAVAIL    The specified address is not
  6521.                               available from the local
  6522.                               machine.
  6523.           
  6524.           WSAEAFNOSUPPORT     Addresses in the specified
  6525.                               family cannot be used with
  6526.                               this socket.
  6527.           
  6528.           WSAEDESTADDRREQ     A destination address is
  6529.                               required.
  6530.           
  6531.           WSAENETUNREACH      The network can't be reached
  6532.                               from this host at this time.
  6533.           
  6534. See Also  WSPSocket()
  6535. 3.1.2.214 WSPSetBlockingHook32()
  6536.  
  6537. Description    Establish an application-specific blocking
  6538.           hook function.
  6539.  
  6540.           #include <ws2spi.h>
  6541.  
  6542.           LPBLOCKINGPRC WSPAPI WSPSetBlockingHook32 (
  6543.           LPBLOCKINGPROC lpBlockFunc, int FAR * lpErrno );
  6544.           
  6545.           lpBlockFunc    A pointer toot the procedure
  6546.                     instance address of the blocking
  6547.                     function to be installed.
  6548.  
  6549.           lpErrno   A pointer to the error code.
  6550.  
  6551. Remarks   This function is only applicable to the 32-bit
  6552. SPIis only available in the 32-bit SPI.
  6553.           
  6554.           This function installs a new function which the
  6555.           Winsock Service Provider should use to implement
  6556.           blocking socket function calls.
  6557.           
  6558.           Winsock Service Providers include a default
  6559.           mechanism by which blocking socket functions are
  6560.           implemented. The function WSPSetBlockingHook32()
  6561.           gives the application the ability to execute its
  6562.           own function at "blocking" time in place of the
  6563.           default function.
  6564.           
  6565.           When an application invokes a blocking Windows
  6566.           Sockets API operation, the Winsock Service
  6567.           Provider initiates the operation and then enters a
  6568.           loop which is similar to the following pseudocode:
  6569.           
  6570.           for(;;) {
  6571.                /* flush messages for good user response */
  6572.                while(BlockingHook())
  6573.                     ;
  6574.                /* check for WSPCancelBlockingCall32() */
  6575.                if(operation_cancelled())
  6576.                     break;
  6577.                /* check to see if operation completed */
  6578.                if(operation_complete())
  6579.                     break;     /* normal completion */
  6580.           }
  6581.           
  6582.           Note that Winsock Service Providers may perform
  6583.           the above steps in a different order; for example,
  6584.           the check for operation complete may occur before
  6585.           calling the blocking hook. The default
  6586.           BlockingHook() function is equivalent to:
  6587.           
  6588.           BOOL DefaultBlockingHook(void) {
  6589.                MSG msg;
  6590.                BOOL ret;
  6591.                /* get the next message if any */
  6592.                ret =
  6593.           (BOOL)PeekMessage(&msg,NULL,0,0,PM_REMOVE);
  6594.                /* if we got one, process it */
  6595.                if (ret) {
  6596.                     TranslateMessage(&msg);
  6597.                     DispatchMessage(&msg);
  6598.                }
  6599.                /* TRUE if we got a message */
  6600.                return ret;
  6601.           }
  6602.           
  6603.           The WSPSetBlockingHook32() function is provided to
  6604.           support those applications which require more
  6605.           complex message processing - for example, those
  6606.           employing the MDI (multiple document interface)
  6607.           model. It is not intended as a mechanism for
  6608.           performing general applications functions. In
  6609.           particular, the only Windows Sockets SPI function
  6610.           which may be issued from a custom blocking hook
  6611.           function is WSPCancelBlockingCall32(), which will
  6612.           cause the blocking loop to terminate.
  6613.           
  6614.           This function must be implemented on a per-thread
  6615.           basis for multithreaded versions of Windows such
  6616.           as Windows NT. It thus provides for a particular
  6617.           thread to replace the blocking mechanism without
  6618.           affecting other threads.
  6619.           
  6620.           In multithreaded versions of Windows, there is no
  6621.           default blocking hook--blocking calls block the
  6622.           thread that makes the call. However, an
  6623.           application may install a specific blocking hook
  6624.           by calling WSPSetBlockingHook32(). This allows
  6625.           easy portability of applications that depend on
  6626.           the blocking hook behavior.
  6627.           
  6628. Return Value   The return value is a pointer to the
  6629.           procedure-instance of the previously installed
  6630.           blocking function. The Winsock DLL should save
  6631.           this return value so that it can be restored if
  6632.           necessary. (If "nesting" is not important, the
  6633.           Winsock DLL may simply discard the value returned
  6634.           by WSPSetBlockingHook32() and eventually use
  6635.           WSPUnhookBlockingHook32() to restore the default
  6636.           mechanism.) If the operation fails, a NULL pointer
  6637.           is returned, and a specific error code is
  6638.           available in lpErrno.
  6639.           On a blocking socket, the return value indicates
  6640.           success or failure of the connection attempt.
  6641.           
  6642.  
  6643. Comments  Attempting to call PSCleanup() from within a
  6644.           blocking hook and then failing to check the return
  6645.           code is a common PII programming error.  If an
  6646.           application needs to quit while a blocking call is
  6647.           outstanding, the application must first cancel the
  6648.           blocking call with PSCancelBlockingCall() then
  6649.           issue the PSCleanup() call once control has been
  6650.           returned to the application.
  6651.  
  6652. Error Codes                   WSANOTINITIALISED   A
  6653.                               successful WSPStartup() must
  6654.                               occur before using this SPI.
  6655.           
  6656.           WSAENETDOWN         The Windows Sockets
  6657.                               implementation has detected
  6658.                               that the network subsystem has
  6659.                               failed.
  6660.           
  6661.           WSAEINPROGRESS      A blocking Windows Sockets
  6662.                               operation is in progress.
  6663. WSANOTINITIALISED             A successful PSStartup() must
  6664.                               occur before using this SPI.
  6665.           
  6666.           
  6667. See Also  WSPCancelBlockingCall32(), WSPIsBlocking32(),
  6668.           WSPUnhookBlockingHook32()
  6669. 3.1.2.215 WSPSocket()
  6670.  
  6671. Description    Create a socket which is bound to a specific
  6672.           transport service provider.
  6673.  
  6674. { May be revised to use PROTOCOL_INFO as an input param in
  6675.           place of af, type, protocol parameters}
  6676.  
  6677.           #include <ws2spiinsock2.h>
  6678.  
  6679.           SOCKET WSPAPI WSPSocket ( int af, int type, int
  6680.           protocol, DWORD dwProviderId, int nFlags, int FAR
  6681.           * lpErrno );
  6682.  
  6683.           
  6684.           af        An address family specification. The
  6685.                     only format currently supported is
  6686.                     PF_INET, which is the ARPA Internet
  6687.                     address format.
  6688.           
  6689.           type      A type specification for the new socket.
  6690.           
  6691.           protocol  A particular protocol to be used with
  6692.                     the socket, or 0 if the caller does not
  6693.                     wish to specify a protocol.
  6694.           
  6695.           dwProviderId   An opaque value returned by the
  6696.                     WSAEnumProtocolsEnumProtocols() API that
  6697.                     identifies a unique service provider.
  6698.                     This information is useful to provider
  6699.                     implementations that present multiple
  6700.                     service provider appearances to Winsock.
  6701.           
  6702.           iFlags    The socket attribute specification.
  6703.           
  6704.           lpErrno   A pointer to the error code.
  6705.  
  6706. Remarks   WSPSocket() causes a socket descriptor and any
  6707.           related resources to be allocated and bound to the
  6708.           transport service provider specified by
  6709.           dwProviderId. If protocol is not specified (i.e.,
  6710.           equal to zero), the default for the specified
  6711.           socket type is used. However, the address family
  6712.           may be given as AF_UNSPEC (unspecified), in which
  6713.           case the protocol parameter must be specified. The
  6714.           protocol number to use is particular to the
  6715.           "communication domain'' in which communication is
  6716.           to take place.
  6717.           
  6718.           {The new name res stuff should obviate the need to
  6719.           enumerate the list of supported socket types here}
  6720.           
  6721.           The following type specifications may be supported
  6722.           (all sockets are bi-directional unless specified
  6723.           otherwise):
  6724.           
  6725.            Type                    Explanation
  6726.            SOCK_STREAM             Alias for
  6727.                                     SOCK_REL_STREAM.
  6728.            
  6729.            SOCK_DGRAM              Alias for
  6730.                                     SOCK_UNREL_DGRAM.
  6731.            
  6732.            SOCK_SEQPACKET          Alias for
  6733.                                     SOCK_REL_DSTREAM.
  6734.            
  6735.            SOCK_RAW                Raw socket.
  6736.            
  6737.            SOCK_REL_STREAM         Connection-oriented
  6738.                                     reliable, unduplicated,
  6739.                                     sequenced, byte
  6740.                                     streamwith an out-of-
  6741.                                     band data transmission
  6742.                                     mechanism.  Uses TCP
  6743.                                     for the Internet
  6744.                                     address family.
  6745.            
  6746.            SOCK_REL_DSTREAM        Connection-oriented
  6747.                                     reliable, unduplicated,
  6748.                                     sequenced, message
  6749.                                     streamwith an out-of-
  6750.                                     band data transmission
  6751.                                     mechanism.
  6752.            
  6753.            SOCK_UNREL_DSTREAM      Connection-oriented
  6754.                                     unreliable,
  6755.                                     unduplicated,
  6756.                                     sequenced, message
  6757.                                     streamwith an out-of-
  6758.                                     band data transmission
  6759.                                     mechanism.
  6760.            
  6761.            SOCK_REL_UNISEND_DSTREAMConnection-oriented,
  6762.                                     reliable, one-way (send
  6763.                                     only), unduplicated,
  6764.                                     sequenced, message
  6765.                                     stream. The matching
  6766.                                     socket at the remote
  6767.                                     side need to be of
  6768.                                     style
  6769.                                     SOCK_REL_UNIRECV_DSTREA
  6770.                                     M.
  6771.            
  6772.            SOCK_REL_UNIRECV_DSTREAMConnection-oriented,
  6773.                                     reliable, one-way
  6774.                                     (receive only),
  6775.                                     unduplicated,
  6776.                                     sequenced, message
  6777.                                     stream.  The matching
  6778.                                     socket at the remote
  6779.                                     side need to be of
  6780.                                     style
  6781.                                     SOCK_REL_UNISEND_DSTREA
  6782.                                     M.
  6783.            
  6784.            SOCK_UNREL_UNISEND_DSTREAM   Connection-
  6785.                                     oriented, unreliable,
  6786.                                     one-way (send only),
  6787.                                     unduplicated,
  6788.                                     sequenced, message
  6789.                                     stream. The matching
  6790.                                     socket at the remote
  6791.                                     side need to be of
  6792.                                     style
  6793.                                     SOCK_UNREL_UNIRECV_DSTR
  6794.                                     EAM.
  6795.            
  6796.            SOCK_UNREL_UNIRECV_DSTREAM   Connection-
  6797.                                     oriented, unreliable,
  6798.                                     one-way (receive only),
  6799.                                     unduplicated,
  6800.                                     sequenced, message
  6801.                                     stream.  The matching
  6802.                                     socket at the remote
  6803.                                     side need to be of
  6804.                                     style
  6805.                                     SOCK_UNREL_UNISEND_DSTR
  6806.                                     EAM.
  6807.            
  6808.            SOCK_REL_DGRAM          Connectionless,
  6809.                                     reliable, datagram.
  6810.            
  6811.            SOCK_UNREL_DGRAM        Connectionless,
  6812.                                     unreliable, datagram.
  6813.            
  6814.            SOCK_REL_ISOCH_DSTREAM  Connection-oriented
  6815.                                     reliable, unduplicated,
  6816.                                     sequenced, isochronous,
  6817.                                     message streamwith an
  6818.                                     out-of-band data
  6819.                                     transmission mechanism.
  6820.            
  6821.            SOCK_UNREL_ISOCH_DSTREAMConnection-oriented
  6822.                                     unreliable,
  6823.                                     unduplicated,
  6824.                                     sequenced, isochronous,
  6825.                                     message streamwith an
  6826.                                     out-of-band data
  6827.                                     transmission mechanism.
  6828.            
  6829.            SOCK_UNREL_ISOCH_STREAM Connection-oriented
  6830.                                     unreliable,
  6831.                                     unduplicated,
  6832.                                     sequenced, isochronous,
  6833.                                     byte streamwith an out-
  6834.                                     of-band data
  6835.                                     transmission mechanism.
  6836.               
  6837.           The iFlags parameter may be used to specify the
  6838.           attributes of the socket by or-ing any of the
  6839.           following Flags:
  6840.  
  6841.           Flag      Meaning
  6842.           WSA_FLAG_OVERLAPPED
  6843.                     This flag causes an overlapped socket to
  6844.                     be created. Overlapped sockets must
  6845.                     utilize the overlapped I/O features of
  6846.                     the WSPSendWSPsend(),
  6847.                     WSPSendToWSPsendto(), WSPRecvWSPrecv(),
  6848.                     WSPRecvFromWSPrecvfrom() SPI for I/O
  6849.                     operations, and allows multiple of these
  6850.                     to be initiated and in progress
  6851.                     simultaneously. Overlapped sockets are
  6852.                     always non-blocking.
  6853.           
  6854.           Connection-oriented sockets such as SOCK_STREAM
  6855.           provide full-duplex connections, and must be in a
  6856.           connected state before any data may be sent or
  6857.           received on it. A connection to another socket is
  6858.           created with a connect() call. Once connected,
  6859.           data may be transferred using WSPSendWSPsend() and
  6860.           WSPRecvWSPrecv() calls. When a session has been
  6861.           completed, a WSPCloseSocketWSPclosesocket() must
  6862.           be performed. Out-of-band data may also be
  6863.           transmitted as described in send() and received as
  6864.           described in recv().
  6865.           
  6866.           The communications protocols used to implement a
  6867.           reliable, connection-oriented socket ensure that
  6868.           data is not lost or duplicated. If data for which
  6869.           the peer protocol has buffer space cannot be
  6870.           successfully transmitted within a reasonable
  6871.           length of time, the connection is considered
  6872.           broken and subsequent calls will fail with the
  6873.           error code set to WSAETIMEDOUT.
  6874.           
  6875.           Connectionless, message-oriented sockets allow
  6876.           sending and receiving of datagrams to and from
  6877.           arbitrary peers using WSPSendToWSPsendto() and
  6878.           WSPRecvFromWSPrecvfrom(). If such a socket is
  6879.           connect()ed to a specific peer, datagrams may be
  6880.           send to that peer using WSPSendWSPsend() and may
  6881.           be received from (only) this peer using
  6882.           WSPRecvWSPrecv().
  6883.  
  6884.  
  6885. Return Value   If no error occurs, WSPSocket() returns a
  6886.           descriptor referencing the new socket. Otherwise,
  6887.           a value of INVALID_SOCKET is returned, and a
  6888.           specific error code is available in lpErrno.
  6889.  
  6890. Error Codes                   WSANOTINITIALISED   A
  6891.                               successful WSPStartup() must
  6892.                               occur before using this SPI.
  6893.           
  6894.           WSAENETDOWN         The network subsystem has
  6895.                               failed.
  6896.           
  6897.           WSAEAFNOSUPPORT     The specified address family
  6898.                               is not supported.
  6899.           
  6900.           WSAEINPROGRESS      A blocking Winsock call is in
  6901.                               progress, or the service
  6902.                               provider is still processing a
  6903.                               callback function.
  6904.           
  6905.           WSAEMFILE           No more socket descriptors are
  6906.                               available.
  6907.           
  6908.           WSAENOBUFS          No buffer space is available.
  6909.                               The socket cannot be created.
  6910.           
  6911.           WSAEPROTONOSUPPORT  The specified protocol is not
  6912.                               supported.
  6913.           
  6914.           WSAEPROTOTYPE       The specified protocol is the
  6915.                               wrong type for this socket.
  6916.           
  6917.           WSAESOCKTNOSUPPORT  The specified socket type is
  6918.                               not supported in this address
  6919.                               family.
  6920.  
  6921. See Also  WSPAccept, WSPBindWSPbind(), WSPConnect(),
  6922.           WSPGetSockNameWSPgetsockname(),
  6923.           WSPGetSockOptWSPgetsockopt(),
  6924.           WSPSetSockOptWSPsetsockopt(),
  6925.           WSPListenWSPlisten(), WSPRecvWSPrecv(),
  6926.           WSARecvFrom(), WSASend(), WSASendToWSASentTo(),
  6927.           WSPShutdownWSPshutdown(),
  6928.           WSPIoctlSocketWSPioctlsocket().
  6929.  
  6930. 3.1.2.216 WSPStartup()
  6931.  
  6932. Description
  6933.  
  6934.           #include <ws2spi.h>
  6935.  
  6936.           int WSPAPI WSPStartup ( WORD wVersionRequested,
  6937.           LPWSADATA lpWSAData );
  6938.  
  6939.           
  6940.           wVersionRequested   The highest version of Winsock
  6941.                          SPI support that the caller can
  6942.                          use. The high order byte specifies
  6943.                          the minor version (revision)
  6944.                          number; the low-order byte
  6945.                          specifies the major version number.
  6946.           
  6947.           lpWSAData      A pointer to the WSADATA data
  6948.                          structure that is to receive
  6949.                          details of the Winsock service
  6950.                          provider.
  6951.  
  6952. Remarks   This function MUST be the first Winsock SPI
  6953.           function called by the Winsock DLL. It allows the
  6954.           Winsock DLL to specify the version of Winsock SPI
  6955.           required and to retrieve details of the specific
  6956.           Winsock service provider implementation. The
  6957.           Winsock DLL may only issue further Winsock SPI
  6958.           functions after a successful WSPStartup()
  6959.           invocation.
  6960.  
  6961.           In order to support future Winsock service
  6962.           providers and the Winsock DLL which may have
  6963.           functionality differences from the current Winsock
  6964.           SPI, a negotiation takes place in WSPStartup().
  6965.           The caller of WSPStartup() (namely, the Winsock
  6966.           DLL) and the Winsock service provider indicate to
  6967.           each other the highest version that they can
  6968.           support, and each confirms that the other's
  6969.           highest version is acceptable. Upon entry to
  6970.           WSPStartup(), the Winsock service provider
  6971.           examines the version requested by the Winsock DLL.
  6972.           If this version is higher than the lowest version
  6973.           supported by the service provider, the call
  6974.           succeeds and the service provider returns in
  6975.           wHighVersion the highest version it supports and
  6976.           in wVersion the minimum of its high version and
  6977.           wVersionRequested. The Winsock service provider
  6978.           then assumes that the Winsock DLL will use
  6979.           wVersion. If the wVersion field of the WSADATA
  6980.           structure is unacceptable to the caller, it should
  6981.           call WSPCleanup() and either search for another
  6982.           Winsock service provider or fail to initialize.
  6983.           
  6984.           This negotiation allows both a Winsock service
  6985.           provider and the Winsock DLL to support a range of
  6986.           Winsock versions. The Winsock DLL can successfully
  6987.           utilize a Winsock service provider if there is any
  6988.           overlap in the version ranges. The following chart
  6989.           gives examples of how WSPStartup() works in
  6990.           conjunction with different DLL and Winsock service
  6991.           provider (SP) versions:
  6992.  
  6993.           DLL     SP      wVersionR wVer  wHighV  End Result
  6994.           versio  Versio  equested  sion  ersion
  6995.           ns      ns
  6996.           1.1     1.1     1.1       1.1   1.1     use 1.1
  6997.           1.0     1.0     1.1       1.0   1.0     use 1.0
  6998.           1.1
  6999. 1.0               1.0 1.1 1.0       1.0   1.1     use 1.0
  7000.           1.1     1.0     1.1       1.1   1.1     use 1.1
  7001.                   1.1
  7002.           1.1     1.0     1.1       1.0   1.0     DLL fails
  7003.           1.0     1.1     1.0       ---   ---     WSAVERNOTSUPPO
  7004.                                                   RTED
  7005.           1.0     1.0     1.1       1.1   1.1     use 1.1
  7006.           1.1     1.1
  7007.           1.1     1.1     2.0       1.1   1.1     use 1.1
  7008.           2.0
  7009. 2.0               1.1     2.0       1.1   1.1     DLL fails
  7010.           
  7011.           The following code fragment demonstrates how a DLL
  7012.           which supports only version 1.1 of Winsock SPI
  7013.           makes a WSPStartup() call:
  7014.           
  7015.           WORD wVersionRequested;
  7016.           WSADATA WSAData;
  7017.           int err;
  7018.           
  7019.           wVersionRequested = MAKEWORD( 1, 1 );
  7020.           
  7021.           err = WSPStartup( wVersionRequested, &WSAData );
  7022.           if ( err != 0 ) {
  7023.               /* Tell the user that we couldn't find a
  7024.           useable */
  7025.               /* Winsock service provider.
  7026.           */
  7027.               return;
  7028.           }
  7029.           
  7030.           /* Confirm that the Winsock service provider
  7031.           supports 1.1.*/
  7032.           /* Note that if the service provider supports
  7033.           versions greater    */
  7034.           /* than 1.1 in addition to 1.1, it will still
  7035.           return */
  7036.           /* 1.1 in wVersion since that is the version we
  7037.           */
  7038.           /* requested.
  7039.           */
  7040.           
  7041.           if ( LOBYTE( WSAData.wVersion ) != 1 ||
  7042.                    HIBYTE( WSAData.wVersion ) != 1 ) {
  7043.               /* Tell the user that we couldn't find a
  7044.           useable */
  7045.               /* Winsock service provider.
  7046.           */
  7047.               WSPCleanup( );
  7048.               return;
  7049.           }
  7050.           
  7051.           /* The Winsock service provider is acceptable.
  7052.           Proceed. */
  7053.           
  7054.           And this code fragment demonstrates how a Winsock
  7055.           service provider which supports only version 1.1
  7056.           performs the WSPStartup() negotiation:
  7057.           
  7058.           /* Make sure that the version requested is >= 1.1.
  7059.           */
  7060.           /* The low byte is the major version and the high
  7061.           */
  7062.           /* byte is the minor version.
  7063.           */
  7064.           
  7065.           if ( LOBYTE( wVersionRequested ) < 1 ||
  7066.                ( LOBYTE( wVersionRequested ) == 1 &&
  7067.                  HIBYTE( wVersionRequested ) < 1 ) {
  7068.               return WSAVERNOTSUPPORTED;
  7069.           }
  7070.           
  7071.           /* Since we only support 1.1, set both wVersion
  7072.           and  */
  7073.           /* wHighVersion to 1.1.
  7074.           */
  7075.           
  7076.           lpWSAData->wVersion = MAKEWORD( 1, 1 );
  7077.           lpWSAData->wHighVersion = MAKEWORD( 1, 1 );
  7078.           
  7079.           Once the Winsock DLL has made a successful
  7080.           WSPStartup() call, it may proceed to make other
  7081.           Winsock SPI calls as needed. When it has finished
  7082.           using the services of the Winsock service
  7083.           provider, the Winsock DLL must call WSPCleanup()
  7084.           in order to allow the Winsock service provider to
  7085.           free any resources for the Winsock DLL.
  7086.  
  7087.           Details of the actual Winsock service provider are
  7088.           described in the WSAData structure defined as
  7089.           follows:
  7090.           
  7091.           {If we remove iMaxSockets & iMaxUdpDg, should we
  7092.           rename the structure to WSAData2 to avoid
  7093.           confusion with the Winsock 1.1 WSAData?}
  7094.           
  7095.           struct WSAData {
  7096.                WORD           wVersion;
  7097.                WORD           wHighVersion;
  7098.                char
  7099.           szDescription[WSADESCRIPTION_LEN+1];
  7100.                char
  7101.           szSystemStatus[WSASYSSTATUS_LEN+1];
  7102.                unsigned short iMaxSockets;
  7103.                unsigned short iMaxUdpDg;
  7104.                char FAR *          lpVendorInfo;
  7105.           };
  7106.           
  7107.           The members of this structure are:
  7108.           Element   Usage
  7109.           wVersion  The version of the Winsock SPI
  7110.                     specification that the Winsock service
  7111.                     provider expects the caller to use.
  7112.           wHighVersion   The highest version of the Winsock
  7113.                     SPI specification that this service
  7114.                     provider can support (also encoded as
  7115.                     above). Normally this will be the same
  7116.                     as wVersion.
  7117.           szDescription  A null-terminated ASCII string into
  7118.                     which the Winsock DLL copies a
  7119.                     description of the Winsock service
  7120.                     provider. The text (up to 256 characters
  7121.                     in length) may contain any characters
  7122.                     except control and formatting
  7123.                     characters: the most likely use that an
  7124.                     application will put this to is to
  7125.                     display it (possibly truncated) in a
  7126.                     status message.
  7127.           szSystemStatus A null-terminated ASCII string into
  7128.                     which the Winsock service provider
  7129.                     copies relevant status or configuration
  7130.                     information. The Winsock service
  7131.                     provider should use this field only if
  7132.                     the information might be useful to the
  7133.                     user or support staff: it should not be
  7134.                     considered as an extension of the
  7135.                     szDescription field.
  7136.           iMaxSockets    The maximum number of sockets which
  7137.                     a single process can potentially open. A
  7138.                     Winsock service provider may provide a
  7139.                     global pool of sockets for allocation to
  7140.                     any process; alternatively it may
  7141.                     allocate per-process resources for
  7142.                     sockets. The number may well reflect the
  7143.                     way in which the Winsock service
  7144.                     provider or the networking software was
  7145.                     configured. Application writers may use
  7146.                     this number as a crude indication of
  7147.                     whether the Winsock service provider is
  7148.                     usable by the application. For example,
  7149.                     an X Windows server might check
  7150.                     iMaxSockets when first started: if it is
  7151.                     less than 8, the application would
  7152.                     display an error message instructing the
  7153.                     user to reconfigure the networking
  7154.                     software. (This is a situation in which
  7155.                     the szSystemStatus text might be used.)
  7156.                     Obviously there is no guarantee that a
  7157.                     particular application can actually
  7158.                     allocate iMaxSockets sockets, since
  7159.                     there may be other Winsock applications
  7160.                     in use.
  7161.           iMaxUdpDg This value is retained for compatibility
  7162.                     with Windows Sockets specification 1.1,
  7163.                     but should not be used when developing
  7164.                     new applications. The value supplied
  7165.                     here will always be 512, the minimum
  7166.                     allowed. For the actual maximum message
  7167.                     size specific to a particular Winsock
  7168.                     service provider and socket type, the
  7169.                     Winsock DLL should use
  7170.                     WSPGetSockOptWSPgetsockopt() to retrieve
  7171.                     the value of option SO_MAX_DG_SIZE after
  7172.                     a socket has been created. The minimum
  7173.                     value of iMaxUdpDg for a compliant PII
  7174.                     implementation is 512.  Note that
  7175.                     regardless of the value of iMaxUdpDg, it
  7176.                     is inadvisable to attempt to send a
  7177.                     broadcast datagram which is larger than
  7178.                     the Maximum Transmission Unit (MTU) for
  7179.                     the network.  (The PII  does not provide
  7180.                     a mechanism to discover the MTU, but it
  7181.                     must be no less than 512 bytes.)
  7182.           lpVendorInfo   This value should be ignored. It is
  7183.                     retained for compatibility with Windows
  7184.                     Sockets specification 1.1. The Winsock
  7185.                     DLL needing to access vendor-specific
  7186.                     configuration information should use
  7187.                     WSPGetSockOptWSPgetsockopt() to retrieve
  7188.                     the value of option PVD_CONFIG. The
  7189.                     definition of this value (if utilized)
  7190.                     is beyond the scope of this
  7191.                     specification.
  7192.           
  7193.           A PII.DLL may call PSStartup() more than once if
  7194.           it needs to obtain the WSAData structure
  7195.           information more than once.  However, the
  7196.           wVersionRequired parameter is assumed to be the
  7197.           same on all calls to PSStartup(); that is, a
  7198.           PII.DLL cannot change the version of PII SPI it
  7199.           expects after the initial call to PSStartup().
  7200.           
  7201.           There must be one PSCleanup() call corresponding
  7202.           to every PSStartup() call to allow third-party
  7203.           DLLs to make use of a PII.DLL on behalf of an
  7204.           application.  This means, for example, that if an
  7205.           application calls PSStartup() three times, it must
  7206.           call PSCleanup() three times.  The first two calls
  7207.           to PSCleanup() do nothing except decrement an
  7208.           internal counter; the final PSCleanup() call for
  7209.           the task does all necessary resource deallocation
  7210.           for the task.
  7211.  
  7212.  
  7213. Return Value   WSPStartup() returns zero if successful.
  7214.           Otherwise it returns one of the error codes listed
  7215.           below. Note that the normal mechanism whereby the
  7216.           application calls PSGetLastError() to determine
  7217.           the error code cannot be used, since the PII.DLL
  7218.           may not have established the client data area
  7219.           where the "last error" information is stored.
  7220.  
  7221. Notes For
  7222. Winsock Service
  7223. Providers The Winsock DLL will make one and only one
  7224.           WSPStartup() call before issuing any other Winsock
  7225.           SPI calls for each Winsock service provider. This
  7226.           function can thus be utilized for initialization
  7227.           purposes.
  7228.           
  7229.           Further issues are discussed in the notes for
  7230.           WSPCleanup().
  7231.  
  7232. Error Codes                   WSASYSNOTREADY Indicates that
  7233.                               the underlying network
  7234.                               subsystem is not ready for
  7235.                               network communication.
  7236.  
  7237.           WSAVERNOTSUPPORTED  The version of Winsock SPI
  7238.                               support requested is not
  7239.                               provided by this particular
  7240.                               Winsock service provider.
  7241.           
  7242.           WSAEFAULT           The lpWSAData parameter is
  7243.                               invalid.
  7244.           
  7245.           WSAEINVAL           The PII version specified by
  7246.                               the application is not
  7247.                               supported by this DLL.
  7248.  
  7249. See Also  WSPSendWSPsend(), WSPSendToWSPsendto(),
  7250.           WSPCleanup()
  7251. 3.1.2.217 WSPUnhookBlockingHook32()
  7252.  
  7253. Description    Restores the default blocking hook function.
  7254.  
  7255.           #include <ws2spi.h>
  7256.  
  7257.           int WSPAPI WSPUnhookBlockingHook32 ( int FAR *
  7258.           lpErrno );
  7259.           
  7260.           lpErrno   A pointer to the error code.
  7261.  
  7262. Remarks   This function is only applicable to the 32-bit
  7263. SPIis only available in the 32-bit SPI.
  7264.           
  7265.           This function removes any previous blocking hook
  7266.           that has been installed and reinstalls the default
  7267.           blocking mechanism.
  7268.           
  7269.           This function is only applicable to the 32-bit
  7270.           SPIis only available in the 32-bit SPI.
  7271.           
  7272.           WSPUnhookBlockingHook32() will always install the
  7273.           default mechanism, not the previous mechanism. If
  7274.           the Winsock DLL wishes to nest blocking hooks -
  7275.           i.e. to establish a temporary blocking hook
  7276.           function and then revert to the previous mechanism
  7277.           (whether the default or one established by an
  7278.           earlier WSPSetBlockingHook32()) - it must save and
  7279.           restore the value returned by
  7280.           WSPSetBlockingHook32(); it cannot use
  7281.           WSPUnhookBlockingHook32().
  7282.           
  7283.           In multithreaded versions of Windows such as
  7284.           Windows NT, there is no default blocking hook.
  7285.           Calling WSPUnhookBlockingHook32() disables any
  7286.           blocking hook installed by the application and any
  7287.           blocking calls made block the thread which made
  7288.           the call.
  7289.  
  7290. Return Value   The return value is 0 if the operation has
  7291.           been successfully initiated. Otherwise the value
  7292.           SOCKET_ERROR is returned, and a specific error
  7293.           number is available in lpErrno.
  7294.           On a blocking socket, the return value indicates
  7295.           success or failure of the connection attempt.
  7296.           
  7297.  
  7298. Comments  Attempting to call PSCleanup() from within a
  7299.           blocking hook and then failing to check the return
  7300.           code is a common PII programming error.  If an
  7301.           application needs to quit while a blocking call is
  7302.           outstanding, the application must first cancel the
  7303.           blocking call with PSCancelBlockingCall() then
  7304.           issue the PSCleanup() call once control has been
  7305.           returned to the application.
  7306.  
  7307. Error Codes                   WSANOTINITIALISED   A
  7308.                               successful PSStartup() must
  7309.                               occur before using this SPI.
  7310.           
  7311.           WSANOTINITIALISED   A successful WSPStartup() must
  7312.                               occur before using this SPI.
  7313.           
  7314. See Also  WSPCancelBlockingCall32(), WSPIsBlocking32(),
  7315.           WSPSetBlockingHook32()
  7316. 4. Upcalls
  7317.  
  7318. This section contains the private "upcalls" that service
  7319. providers may make into the Windows Sockets DLL. All upcalls
  7320. are prefixed with "Xxx" to distinguish them from the normal
  7321. API and SPI entrypoints.
  7322. 4.1 WPUXxxCreateSocketHandle()
  7323.  
  7324. Description    Creates a new socket handle.
  7325.  
  7326.           #include <ws2spi.h>
  7327.  
  7328.           SOCKET WSPAPI WPUXxxCreateSocketHandle ( DWORD
  7329.           dwProviderId, LPVOID lpContext, int FAR * lpErrno
  7330.           );
  7331.  
  7332.           dwProviderId   Identifies the calling service
  7333.                     provider. {We must provide a mechanism
  7334.                     for getting this to the provider,
  7335.                     perhaps at WspStartup() time?}
  7336.           
  7337.           lpContext A context value to associate with the
  7338.                     new socket handle.
  7339.           
  7340.           lpErrno   A pointer to the error code.
  7341.  
  7342. Remarks   This routine creates a new socket handle for the
  7343.           specified provider. The handle returned is Winsock
  7344.           specific; it is not a proper system handle.
  7345.           
  7346.           This routine is only used by providers that do not
  7347.           provide real system handles.
  7348.  
  7349. Return Value   If no error occurs,
  7350.           WPUXxxCreateSocketHandle() returns the new socket
  7351.           handle. Otherwise, it returns INVALID_SOCKET, and
  7352.           a specific error code is available in lpErrno.
  7353.  
  7354. Error Codes                   WSANOTINITIALISED   A
  7355.                               successful PSStartup() must
  7356.                               occur before using this SPI.
  7357.           
  7358.           WSAENOBUFS          Not enough buffers available,
  7359.                               too many sockets.
  7360.  
  7361. See Also  WPUXxxCloseSocketHandle()PSCancelBlockingCall().
  7362. 4.2 WPUXxxCloseSocketHandle()
  7363.  
  7364. Description    Closes an existing socket handle.
  7365.  
  7366.           #include <ws2spi.h>
  7367.  
  7368.           int WSPAPI WPUXxxCloseSocketHandle ( SOCKET s, int
  7369.           FAR * lpErrno );
  7370.  
  7371.           s          Identifies a socket handle created with
  7372.                     WPUXxxCreateSocketHandle().
  7373.           
  7374.           lpErrno   A pointer to the error code.
  7375.  
  7376. Remarks   This routine closes an existing socket handle.
  7377.           This function removes the socket from Winsock's
  7378.           internal socket table. The owning service provider
  7379.           is responsible for releasing any resources
  7380.           associated with the socket.
  7381.  
  7382. Return Value   If no error occurs,
  7383.           WPUXxxCreateSocketHandle() returns 0. Otherwise,
  7384.           it returns SOCKET_ERROR, and a specific error code
  7385.           is available in lpErrno.
  7386.  
  7387. Error Codes                   WSANOTINITIALISED   A
  7388.                               successful PSStartup() must
  7389.                               occur before using this SPI.
  7390.           
  7391.           WSAENOTSOCK         The descriptor is not a socket
  7392.                               created by
  7393.                               WPUXxxCreateSocketHandle().
  7394.  
  7395. See Also  WPUXxxCreateSocketHandle()PSCancelBlockingCall().
  7396. 4.3 WPUXxxQuerySocketHandleContext()
  7397.  
  7398. Description    Queries the context value associated with the
  7399.           specified socket handle.
  7400.  
  7401.           #include <ws2spi.h>
  7402.  
  7403.           int WSPAPI WPUXxxQuerySocketHandleContext ( SOCKET
  7404.           s, LPVOID FAR * lpContext, int FAR * lpErrno );
  7405.  
  7406.           s          Identifies the socket whose context is
  7407.                     to be queried.
  7408.           
  7409.           lpContext A pointer to an LPVOID that will receive
  7410.                     the context value.
  7411.           
  7412.           lpErrno   A pointer to the error code.
  7413.  
  7414. Remarks   This routine queries the current context value
  7415.           associated with the specified socket handle.
  7416.           Service providers typically use this function to
  7417.           retrieve a pointer to provider-specific data
  7418.           associated with the socket. For example, a service
  7419.           provider may use the socket context to store a
  7420.           pointer to a structure containing the socket's
  7421.           state, local and remote transport addresses, event
  7422.           objects for signaling network events, etc.
  7423.  
  7424. Return Value   If no error occurs,
  7425.           WPUXxxQuerySocketHandleContext() returns 0 and
  7426.           stores the current context value in lpContext.
  7427.           Otherwise, it returns SOCKET_ERROR, and a specific
  7428.           error code is available in lpErrno.
  7429.  
  7430. Error Codes                   WSANOTINITIALISED   A
  7431.                               successful PSStartup() must
  7432.                               occur before using this SPI.
  7433.           
  7434.           WSAENOTSOCK         The descriptor is not a socket
  7435.                               created by
  7436.                               WPUXxxCreateSocketHandle().
  7437.  
  7438. See Also  WPUXxxCreateSocketHandle(),
  7439.           WPUXxxSetSocketHandleContext()PSCancelBlockingCall
  7440.           ().
  7441. 4.4 WPUXxxSetSocketHandleContext()
  7442.  
  7443. Description    Sets the context value associated with the
  7444.           specified socket handle.
  7445.  
  7446.           #include <ws2spi.h>
  7447.  
  7448.           int WSPAPI WPUXxxSetSocketHandleContext ( SOCKET
  7449.           s, LPVOID lpContext, int FAR * lpErrno );
  7450.  
  7451.           s          Identifies the socket whose context is
  7452.                     to be set.
  7453.           
  7454.           lpContext The new context value to associate with
  7455.                     the socket.
  7456.           
  7457.           lpErrno   A pointer to the error code.
  7458.  
  7459. Remarks   This routine sets the current context value
  7460.           associated with the specified socket handle.
  7461.  
  7462. Return Value   If no error occurs,
  7463.           WPUXxxSetSocketHandleContext() returns 0 and
  7464.           stores lpContext and the socket's new context
  7465.           value. Otherwise, it returns SOCKET_ERROR, and a
  7466.           specific error code is available in lpErrno.
  7467.  
  7468. Error Codes                   WSANOTINITIALISED   A
  7469.                               successful PSStartup() must
  7470.                               occur before using this SPI.
  7471.           
  7472.           WSAENOTSOCK         The descriptor is not a socket
  7473.                               created by
  7474.                               WPUXxxCreateSocketHandle().
  7475.  
  7476. See Also  WPUXxxCreateSocketHandle(),
  7477.           WPUXxxQuerySocketHandleContext()PSCancelBlockingCa
  7478.           ll().
  7479. 4.5 WPUXxxQueueUserAPC32()
  7480.  
  7481. Description    Queues a user-mode APC against the specified
  7482.           thread.
  7483.  
  7484.           #include <ws2spi.h>
  7485.  
  7486.           int WSPAPI WPUXxxQueueUserAPC32UserAPC ( DWORD
  7487.           dwThreadId, LPWSAUSERAPC lpfnUserApc, DWORD
  7488.           dwContext, int FAR * lpErrno );
  7489.           
  7490.           dwThreadId     Identifies the target thread for
  7491.                     the APC. This is typically a value
  7492.                     returned by the
  7493.                     WPUXxxGetCurrentThreadId() upcall.
  7494.           
  7495.           lpfnUserApc    Points to the function to be called
  7496.                     as a user-mode APC.
  7497.           
  7498.           dwContext A context value to be passed in to the
  7499.                     user-mode APC function.
  7500.           
  7501.           lpErrno   A pointer to the error code.
  7502.  
  7503. Remarks   This routine queues a user-mode APC against the
  7504.           specified thread. The APC will only execute when
  7505.           the specified thread is blocked in an alertable
  7506.           wait. This function is only available in 32 bit
  7507.           versions of the Winsock 2 DLL.
  7508.           
  7509.           LPWSAUSERAPC is defined as follows:
  7510.           
  7511.                typedef VOID (FAR * LPWSAUSERAPC)( DWORD
  7512.                dwContext );
  7513.  
  7514. Return Value   If no error occurs,
  7515.           WPUXxxQueueUserAPC32UserAPC() returns 0 and queues
  7516.           the APC for the specified thread. Otherwise, it
  7517.           returns SOCKET_ERROR, and a specific error code is
  7518.           available in lpErrno.
  7519.  
  7520. Error Codes                   WSANOTINITIALISED   A
  7521.                               successful PSStartup() must
  7522.                               occur before using this SPI.
  7523.           
  7524.           ????                dwThreadId does not specify a
  7525.                               valid thread.
  7526.           
  7527. See Also  WPUXxxGetCurrentThreadId32()PSCancelBlockingCall()
  7528.           .
  7529. 4.6 WPUXxxGetCurrentThreadId32()
  7530.  
  7531. Description    Returns an operating-system specific
  7532.           identifier for the current thread.
  7533.  
  7534.           #include <ws2spi.h>
  7535.  
  7536.           DWORD WSPAPI WPUXxxGetCurrentThreadId32 ( VOID );
  7537.  
  7538. Remarks   This routine returns an operating-system specific
  7539.           identifier for the current thread. The returned
  7540.           value is suitable for use in the
  7541.           WPUXxxQueueUserAPC32UserAPC() upcall.
  7542.           
  7543. Return Value   WPUXxxGetCurrentThreadId32() returns the
  7544.           current thread ID.
  7545.  
  7546. See Also  WPUXxxQueueUserAPC32UserAPC()PSCancelBlockingCall(
  7547.           ).
  7548. 5. Installation APIs
  7549.  
  7550. This section is super preliminary. These APIs will be
  7551. receive additional attention after the December 12th
  7552. meeting.
  7553.  
  7554. 5.1 WPUInstallProvider()
  7555.  
  7556. Description    Installs the specified provider into the
  7557.           system configuration database.
  7558.  
  7559.           #include <ws2spi.h>
  7560.  
  7561.           int WSPAPI WPUInstallProvider( const char FAR *
  7562.           lpszProviderName, const char FAR *
  7563.           lpszProviderDllPath, const PROTOCOL_INFO FAR *
  7564.           lpProtocolInfoList, DWORD dwNumberOfEntries, DWORD
  7565.           FAR * lpdwProviderId, int FAR * lpErrno );
  7566.  
  7567.           lpszProviderName    Points to locally unique name
  7568.                          for this provider. This name must
  7569.                          not conflict with any currently
  7570.                          installed provider.
  7571.           
  7572.           lpszProviderDllPath Points to a fully qualified
  7573.                          path to the provider's DLL image.
  7574.                          The Winsock DLL passes this path
  7575.                          into the LoadLibrary API to load
  7576.                          the provider.
  7577.           
  7578.           lpProtocolInfoList  Points to an array of
  7579.                          PROTOCOL_INFO structures. Each
  7580.                          structure defines a
  7581.                          protocol/address_family/socket_type
  7582.                          supported by the provider.
  7583.           
  7584.           dwNumberOfEntries   Contains the number of entries
  7585.                          in the lpProtocolInfoList array.
  7586.           
  7587.           lpdwProviderId Points to a DWORD that will receive
  7588.                          the locally unique identifier for
  7589.                          the newly installed provider.
  7590.           
  7591.           lpErrno        A pointer to the error code.
  7592.           
  7593. Remarks   This routine creates the necessary common Winsock
  7594.           2 configuration information for the specified
  7595.           provider. After this routine completes
  7596.           successfully, the protocol information provided in
  7597.           lpProtocolInfoList will be returned by the
  7598.           WSAEnumProtocols API.
  7599.           
  7600.           Any file installation or service provider specific
  7601.           configuration information must be performed by the
  7602.           provider setup application.
  7603.           
  7604. Return Value   If no error occurs, WPUInstallProvider()
  7605.           returns 0. Otherwise, it returns SOCKET_ERROR, and
  7606.           a specific error code is available in lpErrno.
  7607.  
  7608. Error Codes                   WSANOTINITIALISED   A
  7609.                               successful PSStartup() must
  7610.                               occur before using this SPI.
  7611.           
  7612.           ????                ????
  7613.           
  7614. See Also  WPUDeinstallProvider(),
  7615.           WSAEnumProtocols()PSCancelBlockingCall().
  7616. 5.2 WPUDeinstallProvider()
  7617.  
  7618. Description    Removes the specified provider from the
  7619.           system configuration database.
  7620.  
  7621.           #include <ws2spi.h>
  7622.  
  7623.           int WSPAPI WPUDeinstallProvider( DWORD
  7624.           dwProviderId, int FAR * lpErrno );
  7625.  
  7626.           dwProviderId   The locally unique identifier of
  7627.                          the provider to deinstall. This
  7628.                          must be a value previously returned
  7629.                          by WPUInstallProvider().
  7630.           
  7631.           lpErrno        A pointer to the error code.
  7632.           
  7633. Remarks   This routine removes the common Winsock 2
  7634.           configuration information for the specified
  7635.           provider. After this routine completes
  7636.           successfully, the protocol information associated
  7637.           with the provider will not be returned by the
  7638.           WSAEnumProtocols API.
  7639.           
  7640.           Any file removal or service provider specific
  7641.           configuration information removal must be
  7642.           performed by the provider setup application.
  7643.           
  7644. Return Value   If no error occurs, WPUDeinstallProvider()
  7645.           returns 0. Otherwise, it returns SOCKET_ERROR, and
  7646.           a specific error code is available in lpErrno.
  7647.  
  7648. Error Codes                   WSANOTINITIALISED   A
  7649.                               successful PSStartup() must
  7650.                               occur before using this SPI.
  7651.           
  7652.           ????                ????
  7653.           
  7654. See Also  WPUInstallProvider(),
  7655.           WSAEnumProtocols()PSCancelBlockingCall().
  7656. Appendix A. Error Codes and Header Files
  7657. A.1 Error Codes
  7658. The following is a list of possible error codes available in
  7659. the lpErrno parameter of each function, along with their
  7660. explanations. The error numbers are consistently set across
  7661. all Winsock-compliant implementations.
  7662.  
  7663. Winsock code   Berkeley       Err  Interpretation
  7664.                equivalent     or
  7665. WSAEINTR       EINTR          100  As in standard C
  7666.                               04
  7667. WSAEBADF       EBADF          100  As in standard C
  7668.                               09
  7669. WSAEACCES      EACCES         100  As in standard C
  7670.                               13
  7671. WSAEFAULT      EFAULT         100  As in standard C
  7672.                               14
  7673. WSAEINVAL      EINVAL         100  As in standard C
  7674.                               22
  7675. WSAEMFILE      EMFILE         100  As in standard C
  7676.                               24
  7677. WSAEWOULDBLOC  EWOULDBLOCK    100  As in BSD
  7678. K                             35
  7679. WSAEINPROGRES  EINPROGRESS    100  This error is returned
  7680. S                             36   if any
  7681.                                    Winsock function is
  7682.                                    called while a blocking
  7683.                                    function is
  7684.                                    in progress.
  7685. WSAEALREADY    EALREADY       100  As in BSD
  7686.                               37
  7687. WSAENOTSOCK    ENOTSOCK       100  As in BSD
  7688.                               38
  7689. WSAEDESTADDRR  EDESTADDRREQ   100  As in BSD
  7690. EQ                            39
  7691. WSAEMSGSIZE    EMSGSIZE       100  As in BSD
  7692.                               40
  7693. WSAEPROTOTYPE  EPROTOTYPE     100  As in BSD
  7694.                               41
  7695. WSAENOPROTOOP  ENOPROTOOPT    100  As in BSD
  7696. T                             42
  7697. WSAEPROTONOSU  EPROTONOSUPPO  100  As in BSD
  7698. PPORT          RT             43
  7699. WSAESOCKTNOSU  ESOCKTNOSUPPO  100  As in BSD
  7700. PPORT          RT             44
  7701. WSAEOPNOTSUPP  EOPNOTSUPP     100  As in BSD
  7702.                               45
  7703. WSAEPFNOSUPPO  EPFNOSUPPORT   100  As in BSD
  7704. RT                            46
  7705. WSAEAFNOSUPPO  EAFNOSUPPORT   100  As in BSD
  7706. RT                            47
  7707. WSAEADDRINUSE  EADDRINUSE     100  As in BSD
  7708.                               48
  7709. WSAEADDRNOTAV  EADDRNOTAVAIL  100  As in BSD
  7710. AIL                           49
  7711. WSAENETDOWN    ENETDOWN       100  As in BSD.  This error
  7712.                               50   may be reported at any
  7713.                                    time if the Winsock
  7714.                                    service provider
  7715.                                    detects an underlying
  7716.                                    failure.
  7717. WSAENETUNREAC  ENETUNREACH    100  As in BSD
  7718. H                             51
  7719. WSAENETRESET   ENETRESET      100  As in BSD
  7720.                               52
  7721. WSAECONNABORT  ECONNABORTED   100  As in BSD
  7722. ED                            53
  7723. WSAECONNRESET  ECONNRESET     100  As in BSD
  7724.                               54
  7725. WSAENOBUFS     ENOBUFS        100  As in BSD
  7726.                               55
  7727. WSAEISCONN     EISCONN        100  As in BSD
  7728.                               56
  7729. WSAENOTCONN    ENOTCONN       100  As in BSD
  7730.                               57
  7731. WSAESHUTDOWN   ESHUTDOWN      100  As in BSD
  7732.                               58
  7733. WSAETOOMANYRE  ETOOMANYREFS   100  As in BSD
  7734. FS                            59
  7735. WSAETIMEDOUT   ETIMEDOUT      100  As in BSD
  7736.                               60
  7737. WSAECONNREFUS  ECONNREFUSED   100  As in BSD
  7738. ED                            61
  7739. WSAELOOP       ELOOP          100  As in BSD
  7740.                               62
  7741. WSAENAMETOOLO  ENAMETOOLONG   100  As in BSD
  7742. NG                            63
  7743. WSAEHOSTDOWN   EHOSTDOWN      100  As in BSD
  7744.                               64
  7745. WSAEHOSTUNREA  EHOSTUNREACH   100  As in BSD
  7746. CH                            65
  7747. WSASYSNOTREAD                 100  Returned by
  7748. Y                             91   WSPStartup()
  7749.                                    indicating that the
  7750.                                    network subsystem is
  7751.                                    unusable.
  7752. WSAVERNOTSUPP                 100  Returned by
  7753. ORTED                         92   WSPStartup()
  7754.                                    indicating that the
  7755.                                    Winsock
  7756.                                    service provider cannot
  7757.                                    support the Winsock
  7758.                                    DLL.
  7759. WSANOTINITIAL                 100  Returned by any
  7760. ISED                          93   function except
  7761.                                    PSStartup() indicating
  7762.                                    that a successful
  7763.                                    PSStartup() has not yet
  7764.                                    been performed.
  7765.  
  7766. WSAHOST_NOT_F  HOST_NOT_FOUN  110  As in BSD.
  7767. OUND           D              01
  7768. WSATRY_AGAIN   TRY_AGAIN      110  As in BSD
  7769.                               02
  7770. WSANO_RECOVER  NO_RECOVERY    110  As in BSD
  7771. Y                             03
  7772. WSANO_DATA     NO_DATA        110  As in BSD
  7773.                               04
  7774.  
  7775.  
  7776. The first set of definitions is present to resolve
  7777. contentions between standard C error codes which may be
  7778. defined inconsistently between various C compilers.
  7779.  
  7780. The second set of definitions provides Winsock versions of
  7781. regular Berkeley Sockets error codes.
  7782.  
  7783. The third set of definitions consists of extended Winsock-
  7784. specific error codes.
  7785.  
  7786. The error numbers are derived from the ws2spi.h header file
  7787. listed in section A.2A.2A.2, and are based on the fact that
  7788. Winsock error numbers are computed by adding 10000 to the
  7789. "normal" Berkeley error number.
  7790.  
  7791. Note that this table does not include all of the error codes
  7792. defined in ws2spi.h. This is because it includes only errors
  7793. which might reasonably be returned by a Winsock service
  7794. provider: ws2spi.h, on the other hand, includes a full set
  7795. of BSD definitions to ensure compatibility with ported
  7796. software.
  7797.  
  7798.  
  7799. A.2 Header Files
  7800. A.2.1 Berkeley Header Files
  7801. A PII service provider who provides a development kit to
  7802. support the development of PII applications must supply a
  7803. set of vestigial header files with names that match a number
  7804. of the header files in the Berkeley software distribution.
  7805. These files are provided for source code compatibility only,
  7806. and each consists of three lines:
  7807.  
  7808. #ifndef _PIISPI_
  7809. #include <PIISPI.h>
  7810. #endif
  7811.  
  7812. The header files provided for compatibility are:
  7813. netdb.h
  7814. arpa/inet.h
  7815. sys/time.h
  7816. sys/socket.h
  7817. netinet/in.h
  7818.  
  7819. The file PIISPI.h contains all of the type and structure
  7820. definitions, constants, macros, and function prototypes used
  7821. by the PII specification.  An application writer may choose
  7822. to ignore the compatibility headers and include PIISPI.h in
  7823. each source file.
  7824.  
  7825.  
  7826.  
  7827. A.2 Winsock SPI Header File - ws2spi.h
  7828.  
  7829. The ws2spi.h header file includes a number of types and
  7830. definitions from the standard Windows header file windows.h.
  7831. The windows.h in the Windows 3.0 SDK (Software Developer's
  7832. Kit) lacks a #include guard, so if you need to include
  7833. windows.h as well as ws2spi.h, you should define the symbol
  7834. _INC_WINDOWS before #including ws2spi.h, as follows:
  7835.           #include <windows.h>
  7836.           #define _INC_WINDOWS
  7837.           #include <ws2spi.h>
  7838. Users of the SDK for Windows 3.1 and later need not do this.
  7839.  
  7840. A Winsock service provider vendor MUST NOT make any
  7841. modifications to this header file which could impact binary
  7842. compatibility of Winsock applications. The constant values,
  7843. function parameters and return codes, and the like must
  7844. remain consistent across all Winsock service provider
  7845. vendors.
  7846.  
  7847.  
  7848. /* WS2SPI.H--definitions to be used with the Winsock service
  7849. provider.
  7850.  *
  7851.  * This header file corresponds to version 2.0 of the
  7852. Winsock SPI specification.
  7853.  *
  7854.  * This file includes parts which are Copyright (c) 1982-
  7855. 1986 Regents
  7856.  * of the University of California.  All rights reserved.
  7857. The
  7858.  * Berkeley Software License Agreement specifies the terms
  7859. and
  7860.  * conditions for redistribution.
  7861.  */
  7862.  
  7863. #ifndef _WS2SPI_
  7864. #define _WS2SPI_
  7865.  
  7866. #ifndef _WS2API_
  7867.  
  7868. /*
  7869.  * Pull in WINDOWS.H if necessary
  7870.  */
  7871. #ifndef _INC_WINDOWS
  7872. #include <windows.h>
  7873. #endif /* _INC_WINDOWS */
  7874.  
  7875. /*
  7876.  * SPI function linkage.
  7877.  */
  7878.  
  7879. #define WSPAPI WSPAPI
  7880.  
  7881. /*
  7882.  * Basic system type definitions, taken from the BSD file
  7883. sys/types.h.
  7884.  */
  7885. typedef unsigned char   u_char;
  7886. typedef unsigned short  u_short;
  7887. typedef unsigned int    u_int;
  7888. typedef unsigned long   u_long;
  7889.  
  7890. /*
  7891.  * The new type to be used in all
  7892.  * instances which refer to sockets.
  7893.  */
  7894. typedef u_int           SOCKET;
  7895.  
  7896. /*
  7897.  * Select uses arrays of SOCKETs.  These macros manipulate
  7898. such
  7899.  * arrays.  FD_SETSIZE may be defined by the user before
  7900. including
  7901.  * this file, but the default here should be >= 64.
  7902.  *
  7903.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST
  7904. BE
  7905.  * INCLUDED IN WS2SPI.H EXACTLY AS SHOWN HERE.
  7906.  */
  7907. #ifndef FD_SETSIZE
  7908. #define FD_SETSIZE      64
  7909. #endif /* FD_SETSIZE */
  7910.  
  7911. typedef struct fd_set {
  7912.         u_short fd_count;               /* how many are SET?
  7913. */
  7914.         SOCKET  fd_array[FD_SETSIZE];   /* an array of
  7915. SOCKETs */
  7916. } fd_set;
  7917.  
  7918. #ifdef __cplusplus
  7919. extern "C" {
  7920. #endif
  7921.  
  7922. extern int WSPAPI __WSAFDIsSet(SOCKET, fd_set FAR *);
  7923.  
  7924. #ifdef __cplusplus
  7925. }
  7926. #endif
  7927.  
  7928. #define FD_CLR(fd, set) do { \
  7929.     u_int __i; \
  7930.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ;
  7931. __i++) { \
  7932.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  7933.             while (__i < ((fd_set FAR *)(set))->fd_count-1)
  7934. { \
  7935.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  7936.                     ((fd_set FAR *)(set))->fd_array[__i+1];
  7937. \
  7938.                 __i++; \
  7939.             } \
  7940.             ((fd_set FAR *)(set))->fd_count--; \
  7941.             break; \
  7942.         } \
  7943.     } \
  7944. } while(0)
  7945.  
  7946. #define FD_SET(fd, set) do { \
  7947.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  7948.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR
  7949. *)(set))->fd_count++]=fd;\
  7950. } while(0)
  7951.  
  7952. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  7953.  
  7954. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set
  7955. FAR *)set)
  7956.  
  7957. /*
  7958.  * Structure used in select() call, taken from the BSD file
  7959. sys/time.h.
  7960.  */
  7961. struct timeval {
  7962.         long    tv_sec;         /* seconds */
  7963.         long    tv_usec;        /* and microseconds */
  7964. };
  7965.  
  7966. /*
  7967.  * Operations on timevals.
  7968.  *
  7969.  * NB: timercmp does not work for >= or <=.
  7970.  */
  7971. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)-
  7972. >tv_usec)
  7973. #define timercmp(tvp, uvp, cmp) \
  7974.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  7975.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec
  7976. cmp (uvp)->tv_usec)
  7977. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)-
  7978. >tv_usec = 0
  7979.  
  7980. /*
  7981.  * Winsock extension
  7982.  */
  7983. #define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) |
  7984. (((WORD)((BYTE)(high))) << 8)))
  7985.  
  7986. /*
  7987.  * Commands for ioctlsocket(),  taken from the BSD file
  7988. fcntl.h.
  7989.  *
  7990.  *
  7991.  * Ioctl's have the command encoded in the lower word,
  7992.  * and the size of any in or out parameters in the upper
  7993.  * word.  The high 2 bits of the upper word are used
  7994.  * to encode the in/out status of the parameter; for now
  7995.  * we restrict parameters to at most 128 bytes.
  7996.  */
  7997. #define IOCPARM_MASK    0x7f            /* parameters must
  7998. be < 128 bytes */
  7999. #define IOC_VOID        0x20000000      /* no parameters */
  8000. #define IOC_OUT         0x40000000      /* copy out
  8001. parameters */
  8002. #define IOC_IN          0x80000000      /* copy in
  8003. parameters */
  8004. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  8005.                                         /* 0x20000000
  8006. distinguishes new &
  8007.                                            old ioctl's */
  8008. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  8009.  
  8010. #define _IOR(x,y,t)
  8011. (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  8012.  
  8013. #define _IOW(x,y,t)
  8014. (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  8015.  
  8016. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to
  8017. read */
  8018. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-
  8019. blocking i/o */
  8020. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear
  8021. async i/o */
  8022.  
  8023. /* Socket I/O Controls */
  8024. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high
  8025. watermark */
  8026. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high
  8027. watermark */
  8028. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low
  8029. watermark */
  8030. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low
  8031. watermark */
  8032. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark?
  8033. */
  8034.  
  8035. /*
  8036.  * Structures returned by network data base library, taken
  8037. from the
  8038.  * BSD file netdb.h.  All addresses are supplied in host
  8039. order, and
  8040.  * returned in network order (suitable for use in system
  8041. calls).
  8042.  */
  8043.  
  8044. struct  hostent {
  8045.         char    FAR * h_name;           /* official name of
  8046. host */
  8047.         char    FAR * FAR * h_aliases;  /* alias list */
  8048.         short   h_addrtype;             /* host address type
  8049. */
  8050.         short   h_length;               /* length of address
  8051. */
  8052.         char    FAR * FAR * h_addr_list; /* list of
  8053. addresses */
  8054. #define h_addr  h_addr_list[0]          /* address, for
  8055. backward compat */
  8056. };
  8057.  
  8058. /*
  8059.  * It is assumed here that a network number
  8060.  * fits in 32 bits.
  8061.  */
  8062. struct  netent {
  8063.         char    FAR * n_name;           /* official name of
  8064. net */
  8065.         char    FAR * FAR * n_aliases;  /* alias list */
  8066.         short   n_addrtype;             /* net address type
  8067. */
  8068.         u_long  n_net;                  /* network # */
  8069. };
  8070.  
  8071. struct  servent {
  8072.         char    FAR * s_name;           /* official service
  8073. name */
  8074.         char    FAR * FAR * s_aliases;  /* alias list */
  8075.         short   s_port;                 /* port # */
  8076.         char    FAR * s_proto;          /* protocol to use
  8077. */
  8078. };
  8079.  
  8080. struct  protoent {
  8081.         char    FAR * p_name;           /* official protocol
  8082. name */
  8083.         char    FAR * FAR * p_aliases;  /* alias list */
  8084.         short   p_proto;                /* protocol # */
  8085. };
  8086.  
  8087. /*
  8088.  * Constants and structures defined by the internet system,
  8089.  * Per RFC 790, September 1981, taken from the BSD file
  8090. netinet/in.h.
  8091.  */
  8092.  
  8093. /*
  8094.  * Protocols
  8095.  */
  8096. #define IPPROTO_IP              0               /* dummy for
  8097. IP */
  8098. #define IPPROTO_ICMP            1               /* control
  8099. message protocol */
  8100. #define IPPROTO_GGP             2               /* gateway^2
  8101. (deprecated) */
  8102. #define IPPROTO_TCP             6               /* tcp */
  8103. #define IPPROTO_PUP             12              /* pup */
  8104. #define IPPROTO_UDP             17              /* user
  8105. datagram protocol */
  8106. #define IPPROTO_IDP             22              /* xns idp
  8107. */
  8108. #define IPPROTO_ND              77              /*
  8109. UNOFFICIAL net disk proto */
  8110.  
  8111. #define IPPROTO_RAW             255             /* raw IP
  8112. packet */
  8113. #define IPPROTO_MAX             256
  8114.  
  8115. /*
  8116.  * Port/socket numbers: network standard functions
  8117.  */
  8118. #define IPPORT_ECHO             7
  8119. #define IPPORT_DISCARD          9
  8120. #define IPPORT_SYSTAT           11
  8121. #define IPPORT_DAYTIME          13
  8122. #define IPPORT_NETSTAT          15
  8123. #define IPPORT_FTP              21
  8124. #define IPPORT_TELNET           23
  8125. #define IPPORT_SMTP             25
  8126. #define IPPORT_TIMESERVER       37
  8127. #define IPPORT_NAMESERVER       42
  8128. #define IPPORT_WHOIS            43
  8129. #define IPPORT_MTP              57
  8130.  
  8131. /*
  8132.  * Port/socket numbers: host specific functions
  8133.  */
  8134. #define IPPORT_TFTP             69
  8135. #define IPPORT_RJE              77
  8136. #define IPPORT_FINGER           79
  8137. #define IPPORT_TTYLINK          87
  8138. #define IPPORT_SUPDUP           95
  8139.  
  8140. /*
  8141.  * UNIX TCP sockets
  8142.  */
  8143. #define IPPORT_EXECSERVER       512
  8144. #define IPPORT_LOGINSERVER      513
  8145. #define IPPORT_CMDSERVER        514
  8146. #define IPPORT_EFSSERVER        520
  8147.  
  8148. /*
  8149.  * UNIX UDP sockets
  8150.  */
  8151. #define IPPORT_BIFFUDP          512
  8152. #define IPPORT_WHOSERVER        513
  8153. #define IPPORT_ROUTESERVER      520
  8154.                                         /* 520+1 also used
  8155. */
  8156.  
  8157. /*
  8158.  * Ports < IPPORT_RESERVED are reserved for
  8159.  * privileged processes (e.g. root).
  8160.  */
  8161. #define IPPORT_RESERVED         1024
  8162.  
  8163. /*
  8164.  * Link numbers
  8165.  */
  8166. #define IMPLINK_IP              155
  8167. #define IMPLINK_LOWEXPER        156
  8168. #define IMPLINK_HIGHEXPER       158
  8169.  
  8170. /*
  8171.  * Internet address (old style... should be updated)
  8172.  */
  8173. struct in_addr {
  8174.         union {
  8175.                 struct { u_char s_b1,s_b2,s_b3,s_b4; }
  8176. S_un_b;
  8177.                 struct { u_short s_w1,s_w2; } S_un_w;
  8178.                 u_long S_addr;
  8179.         } S_un;
  8180. #define s_addr  S_un.S_addr
  8181.                                 /* can be used for most tcp
  8182. & ip code */
  8183. #define s_host  S_un.S_un_b.s_b2
  8184.                                 /* host on imp */
  8185. #define s_net   S_un.S_un_b.s_b1
  8186.                                 /* network */
  8187. #define s_imp   S_un.S_un_w.s_w2
  8188.                                 /* imp */
  8189. #define s_impno S_un.S_un_b.s_b4
  8190.                                 /* imp # */
  8191. #define s_lh    S_un.S_un_b.s_b3
  8192.                                 /* logical host */
  8193. };
  8194.  
  8195. /*
  8196.  * Definitions of bits in internet address integers.
  8197.  * On subnets, the decomposition of addresses to host and
  8198. net parts
  8199.  * is done according to subnet mask, not the masks here.
  8200.  */
  8201. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) ==
  8202. 0)
  8203. #define IN_CLASSA_NET           0xff000000
  8204. #define IN_CLASSA_NSHIFT        24
  8205. #define IN_CLASSA_HOST          0x00ffffff
  8206. #define IN_CLASSA_MAX           128
  8207.  
  8208. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) ==
  8209. 0x80000000)
  8210. #define IN_CLASSB_NET           0xffff0000
  8211. #define IN_CLASSB_NSHIFT        16
  8212. #define IN_CLASSB_HOST          0x0000ffff
  8213. #define IN_CLASSB_MAX           65536
  8214.  
  8215. #define IN_CLASSC(i)            (((long)(i) & 0xc0000000) ==
  8216. 0xc0000000)
  8217. #define IN_CLASSC_NET           0xffffff00
  8218. #define IN_CLASSC_NSHIFT        8
  8219. #define IN_CLASSC_HOST          0x000000ff
  8220.  
  8221. #define INADDR_ANY              (u_long)0x00000000
  8222. #define INADDR_LOOPBACK         0x7f000001
  8223. #define INADDR_BROADCAST        (u_long)0xffffffff
  8224. #define INADDR_NONE             0xffffffff
  8225. /* Winsock extension */
  8226. #define ADDR_ANY                INADDR_ANY
  8227.  
  8228. /*
  8229.  * Socket address, internet style.
  8230.  */
  8231. struct sockaddr_in {
  8232.         short   sin_family;
  8233.         u_short sin_port;
  8234.         struct  in_addr sin_addr;
  8235.         char    sin_zero[8];
  8236. };
  8237.  
  8238. #define WSADESCRIPTION_LEN      256
  8239. #define WSASYS_STATUS_LEN       128
  8240.  
  8241. typedef struct WSAData {
  8242.         WORD                    wVersion;
  8243.         WORD                    wHighVersion;
  8244.         char
  8245. szDescription[WSADESCRIPTION_LEN+1];
  8246.         char
  8247. szSystemStatus[WSASYS_STATUS_LEN+1];
  8248.         unsigned short          iMaxSockets;
  8249.         unsigned short          iMaxUdpDg;
  8250.         char FAR *              lpVendorInfo;
  8251. } WSADATA;
  8252.  
  8253. typedef WSADATA FAR *LPWSADATA;
  8254.  
  8255.  
  8256. /*
  8257.  * Options for use with [gs]etsockopt at the IP level.
  8258.  */
  8259. #define IP_OPTIONS      1               /* set/get IP per-
  8260. packet options */
  8261.  
  8262. /*
  8263.  * Definitions related to sockets: types, address families,
  8264. options,
  8265.  * taken from the BSD file sys/socket.h.
  8266.  */
  8267.  
  8268. /*
  8269.  * This is used instead of -1, since the
  8270.  * SOCKET type is unsigned.
  8271.  */
  8272. #define INVALID_SOCKET  (SOCKET)(~0)
  8273. #define SOCKET_ERROR            (-1)
  8274.  
  8275. /*
  8276.  * Types
  8277.  */
  8278. #define SOCK_STREAM     1               /* stream socket */
  8279. #define SOCK_DGRAM      2               /* datagram socket
  8280. */
  8281. #define SOCK_RAW        3               /* raw-protocol
  8282. interface */
  8283. #define SOCK_RDM        4               /* reliably-
  8284. delivered message */
  8285. #define SOCK_SEQPACKET  5               /* sequenced packet
  8286. stream */
  8287.  
  8288. /*
  8289.  * Types -- Winsock extensions for socket types with the
  8290. following convention
  8291.  *
  8292. SOCK[_REL|_UNREL][_ISOCH][_UNISEND|_UNIRECV][_STREAM|_DGRAM|
  8293. _DSTREAM]
  8294.  */
  8295. #define SOCK_REL_STREAM               SOCK_STREAM
  8296. #define SOCK_REL_DSTREAM              SOCK_SEQPACKET
  8297. #define SOCK_UNREL_DSTREAM            101
  8298. #define SOCK_REL_UNISEND_DSTREAM      102
  8299. #define SOCK_REL_UNIRECV_DSTREAM      103
  8300. #define SOCK_UNREL_UNISEND_DSTREAM    104
  8301. #define SOCK_UNREL_UNIRECV_DSTREAM    105
  8302. #define SOCK_REL_DGRAM                106
  8303. #define SOCK_UNREL_DGRAM              SOCK_DGRAM
  8304. #define SOCK_REL_ISOCH_DSTREAM        201
  8305. #define SOCK_UNREL_ISOCH_DSTREAM      202
  8306. #define SOCK_UNREL_ISOCH_STREAM       203
  8307.  
  8308. /*
  8309.  * Option flags per-socket.
  8310.  */
  8311. #define SO_DEBUG        0x0001          /* turn on debugging
  8312. info recording */
  8313. #define SO_ACCEPTCONN   0x0002          /* socket has had
  8314. listen() */
  8315. #define SO_REUSEADDR    0x0004          /* allow local
  8316. address reuse */
  8317. #define SO_KEEPALIVE    0x0008          /* keep connections
  8318. alive */
  8319. #define SO_DONTROUTE    0x0010          /* just use
  8320. interface addresses */
  8321. #define SO_BROADCAST    0x0020          /* permit sending of
  8322. broadcast msgs */
  8323. #define SO_USELOOPBACK  0x0040          /* bypass hardware
  8324. when possible */
  8325. #define SO_LINGER       0x0080          /* linger on close
  8326. if data present */
  8327. #define SO_OOBINLINE    0x0100          /* leave received
  8328. OOB data in line */
  8329.  
  8330. #define SO_DONTLINGER   (int)(~SO_LINGER)
  8331.  
  8332. /*
  8333.  * Additional options.
  8334.  */
  8335. #define SO_SNDBUF       0x1001          /* send buffer size
  8336. */
  8337. #define SO_RCVBUF       0x1002          /* receive buffer
  8338. size */
  8339. #define SO_SNDLOWAT     0x1003          /* send low-water
  8340. mark */
  8341. #define SO_RCVLOWAT     0x1004          /* receive low-water
  8342. mark */
  8343. #define SO_SNDTIMEO     0x1005          /* send timeout */
  8344. #define SO_RCVTIMEO     0x1006          /* receive timeout
  8345. */
  8346. #define SO_ERROR        0x1007          /* get error status
  8347. and clear */
  8348. #define SO_TYPE         0x1008          /* get socket type
  8349. */
  8350.  
  8351. /*
  8352.  * Winsock extension -- options
  8353.  */
  8354. #define SO_FLOWSPEC       0x2001          /* flow spec for
  8355. sockets */
  8356. #define SO_GROUP_FLOWSPEC 0x2002          /* flow spec for
  8357. socket groups */
  8358. #define SO_GROUP_ID       0x2003          /* sharing the
  8359. same physical connection */
  8360. #define SO_GROUP_PRIORITY 0x2004          /* the relative
  8361. priority with a group */
  8362. #define SO_MAX_DG_SIZE    0x2005          /* maximum
  8363. datagram size */
  8364. #define PVD_CALL_ID       0x3001          /* an opaque
  8365. Winsock call ID */
  8366. #define PVD_CONFIG        0x3002          /* configuration
  8367. info for service provider */
  8368. #define TAPI_DEVICE_ID    0x3003          /* a TAPI line
  8369. device ID */
  8370.  
  8371. /*
  8372.  * TCP options.
  8373.  */
  8374. #define TCP_NODELAY     0x0001
  8375.  
  8376. /*
  8377.  * Address families.
  8378.  */
  8379. #define AF_UNSPEC       0               /* unspecified */
  8380. #define AF_UNIX         1               /* local to host
  8381. (pipes, portals) */
  8382. #define AF_INET         2               /* internetwork:
  8383. UDP, TCP, etc. */
  8384. #define AF_IMPLINK      3               /* arpanet imp
  8385. addresses */
  8386. #define AF_PUP          4               /* pup protocols:
  8387. e.g. BSP */
  8388. #define AF_CHAOS        5               /* mit CHAOS
  8389. protocols */
  8390. #define AF_NS           6               /* XEROX NS
  8391. protocols */
  8392. #define AF_ISO          7               /* ISO protocols */
  8393. #define AF_OSI          AF_ISO          /* OSI is ISO */
  8394. #define AF_ECMA         8               /* european computer
  8395. manufacturers */
  8396. #define AF_DATAKIT      9               /* datakit protocols
  8397. */
  8398. #define AF_CCITT        10              /* CCITT protocols,
  8399. X.25 etc */
  8400. #define AF_SNA          11              /* IBM SNA */
  8401. #define AF_DECnet       12              /* DECnet */
  8402. #define AF_DLI          13              /* Direct data link
  8403. interface */
  8404. #define AF_LAT          14              /* LAT */
  8405. #define AF_HYLINK       15              /* NSC Hyperchannel
  8406. */
  8407. #define AF_APPLETALK    16              /* AppleTalk */
  8408. #define AF_NETBIOS      17              /* NetBios-style
  8409. addresses */
  8410. /*
  8411.  * Address families -- Winsock extensions.
  8412.  */
  8413. #define AF_IPX          18              /* IPX/SPX addresses
  8414. */
  8415. #define AF_POTS_IT      19              /* POTS addresses
  8416. for Intel Transport */
  8417. #define AF_ISDNQMUX_IT  20              /* ISDN addresses
  8418. for Intel Transport */
  8419. #define AF_INET_SPE     21              /* Internet (SPE
  8420. version) */
  8421. #define AF_IPX_SPE      22              /* IPX/SPX (SPE
  8422. version) */
  8423. #define AF_NETBIOS_SPE  23              /* NetBios (SPE
  8424. version) */
  8425.  
  8426. #define AF_MAX          24
  8427.  
  8428. /*
  8429.  * Structure used by kernel to store most
  8430.  * addresses.
  8431.  */
  8432. struct sockaddr {
  8433.         u_short sa_family;              /* address family */
  8434.         char    sa_data[14];            /* up to 14 bytes of
  8435. direct address */
  8436. };
  8437.  
  8438. /*
  8439.  * Structure used by kernel to pass protocol
  8440.  * information in raw sockets.
  8441.  */
  8442. struct sockproto {
  8443.         u_short sp_family;              /* address family */
  8444.         u_short sp_protocol;            /* protocol */
  8445. };
  8446.  
  8447. /*
  8448.  * Protocol families, same as address families for now.
  8449.  */
  8450. #define PF_UNSPEC       AF_UNSPEC
  8451. #define PF_UNIX         AF_UNIX
  8452. #define PF_INET         AF_INET
  8453. #define PF_IMPLINK      AF_IMPLINK
  8454. #define PF_PUP          AF_PUP
  8455. #define PF_CHAOS        AF_CHAOS
  8456. #define PF_NS           AF_NS
  8457. #define PF_ISO          AF_ISO
  8458. #define PF_OSI          AF_OSI
  8459. #define PF_ECMA         AF_ECMA
  8460. #define PF_DATAKIT      AF_DATAKIT
  8461. #define PF_CCITT        AF_CCITT
  8462. #define PF_SNA          AF_SNA
  8463. #define PF_DECnet       AF_DECnet
  8464. #define PF_DLI          AF_DLI
  8465. #define PF_LAT          AF_LAT
  8466. #define PF_HYLINK       AF_HYLINK
  8467. #define PF_APPLETALK    AF_APPLETALK
  8468. /*
  8469.  * Protocol families -- Winsock extension
  8470.  */
  8471. #define PF_IPX          AF_IPX
  8472. #define PF_POTS_IT      AF_POTS_IT
  8473. #define PF_ISDNQMUX_IT  AF_ISDNQMUX_IT
  8474. #define PF_INET_SPE     AF_INET_SPE
  8475. #define PF_IPX_SPE      AF_IPX_SPE
  8476. #define PF_NETBIOS_SPE  AF_NETBIOS_SPE
  8477.  
  8478. #define PF_MAX          AF_MAX
  8479.  
  8480. /*
  8481.  * Structure used for manipulating linger option.
  8482.  */
  8483. struct  linger {
  8484.         u_short l_onoff;                /* option on/off */
  8485.         u_short l_linger;               /* linger time */
  8486. };
  8487.  
  8488. /*
  8489.  * Level number for (get/set)sockopt() to apply to socket
  8490. itself.
  8491.  */
  8492. #define SOL_SOCKET      0xffff          /* options for
  8493. socket level */
  8494.  
  8495. /*
  8496.  * Winsock extension -- level number for
  8497. (get/set)socketopt() to apply to service provider
  8498.  *                  level.
  8499.  */
  8500. #define SOL_PROVIDER    IPPROTO_TCP     /* options for
  8501. service provider level */
  8502.  
  8503. /*
  8504.  * Maximum queue length specifiable by listen.
  8505.  */
  8506. #define SOMAXCONN       5
  8507.  
  8508. #define MSG_OOB         0x1             /* process out-of-
  8509. band data */
  8510. #define MSG_PEEK        0x2             /* peek at incoming
  8511. message */
  8512. #define MSG_DONTROUTE   0x4             /* send without
  8513. using routing tables */
  8514. #define MSG_INTERRUPT   0x8             /* interrupt-time
  8515. send or recv */
  8516.  
  8517. #define MSG_MAXIOVLEN   0x10
  8518.  
  8519. /*
  8520.  * Define constant based on rfc883, used by gethostbyxxxx()
  8521. calls.
  8522.  */
  8523. #define MAXGETHOSTSTRUCT        1024
  8524.  
  8525. /*
  8526.  * Winsock extension -- WSABUF and QOS struct
  8527.  */
  8528. typedef struct _WSABUF {
  8529.      int         len;     /* the length of the buffer */
  8530.      char FAR *  buf;     /* the pointer to the buffer */
  8531. } WSABUF, FAR * LPWSABUF;
  8532.  
  8533. typedef enum _GUARANTEE {
  8534.      GuaranteedService,
  8535.      BestEffortService
  8536. } GUARANTEE;
  8537.  
  8538. typedef struct _flowparams {
  8539.      int64          AverageBandwidth;   /* in bytes/sec */
  8540.      int64          PeakBandwidth;      /* in bytes/sec */
  8541.      int64          BurstLength;        /* in microseconds
  8542. */
  8543.      int64          Latency;       /* in microseconds */
  8544.      int64          DelayVariation;     /* in microseconds
  8545. */
  8546.      GUARANTEE LevelOfGuarantee;   /* guaranteed or best
  8547. effort */
  8548.      int32          CostOfCall          /* reserved for
  8549. future; must be zero */
  8550.      int32          ProviderId;         /* provider
  8551. identifier */
  8552.      int32          SizePSP;       /* length of provider
  8553. specific parameters */
  8554.      UCHAR          ProviderSpecificParams[1]; /* provider
  8555. specific parameters */
  8556. } FLOWPARAMS;
  8557.  
  8558. typedef struct _QOS {
  8559.      FLOWPARAMS     ForwardFP;          /* caller
  8560. (initiator) to callee */
  8561.      FLOWPARAMS     BackwardFP;         /* callee to caller
  8562. */
  8563. } QOS, FAR * LPQOS;
  8564.  
  8565. /*
  8566.  * Winsock extension -- WSANETWORKEVENT
  8567.  */
  8568. typedef struct _WSANETWORKEVENT {
  8569.      BOOL Fired;
  8570.      int  ErrorCode;
  8571. } WSANETWORKEVENT, FAR * LPWSANETWORKEVENT;
  8572.  
  8573. /*
  8574.  * Winsock extension -- manifest constants for the return
  8575. value of the condition function
  8576.  */
  8577. #define CF_ACCEPT       0x0000
  8578. #define CF_REJECT       0x0001
  8579. #define CF_DEFER        0x0002
  8580.  
  8581. /*
  8582.  * Winsock extension -- manifest constants for shutdown()
  8583.  */
  8584. #define SD_RECEIVE      0x00
  8585. #define SD_SEND         0x01
  8586. #define SD_BOTH         0x02
  8587.  
  8588. /*
  8589.  * Winsock extension -- data type and manifest constants for
  8590. socket groups
  8591.  */
  8592. typedef unsigned int             GROUP;
  8593.  
  8594. #define SG_UNCONSTRAINED_GROUP   0x01
  8595. #define SG_CONSTRAINED_GROUP     0x02
  8596.  
  8597. /*
  8598.  * Define flags to be used with the WSPSelect() call.
  8599.  */
  8600. #define FD_READ         0x01L
  8601. #define FD_WRITE        0x02L
  8602. #define FD_OOB          0x04L
  8603. #define FD_ACCEPT       0x08L
  8604. #define FD_CONNECT      0x10L
  8605. #define FD_CLOSE        0x20L
  8606. /*
  8607.  * Winsock extension -- new flags for WSPSelect()
  8608.  */
  8609. #define FD_QOS          0x40L
  8610. #define FD_GROUP_QOS    0x80L
  8611.  
  8612. /*
  8613.  * All Winsock error constants are biased by WSABASEERR from
  8614.  * the "normal"
  8615.  */
  8616. #define WSABASEERR              10000
  8617. /*
  8618.  * Winsock definitions of regular Microsoft C error
  8619. constants
  8620.  */
  8621. #define WSAEINTR                (WSABASEERR+4)
  8622. #define WSAEBADF                (WSABASEERR+9)
  8623. #define WSAEACCES               (WSABASEERR+13)
  8624. #define WSAEFAULT               (WSABASEERR+14)
  8625. #define WSAEINVAL               (WSABASEERR+22)
  8626. #define WSAEMFILE               (WSABASEERR+24)
  8627.  
  8628. /*
  8629.  * Winsock definitions of regular Berkeley error constants
  8630.  */
  8631. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  8632. #define WSAEINPROGRESS          (WSABASEERR+36)
  8633. #define WSAEALREADY             (WSABASEERR+37)
  8634. #define WSAENOTSOCK             (WSABASEERR+38)
  8635. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  8636. #define WSAEMSGSIZE             (WSABASEERR+40)
  8637. #define WSAEPROTOTYPE           (WSABASEERR+41)
  8638. #define WSAENOPROTOOPT          (WSABASEERR+42)
  8639. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  8640. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  8641. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  8642. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  8643. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  8644. #define WSAEADDRINUSE           (WSABASEERR+48)
  8645. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  8646. #define WSAENETDOWN             (WSABASEERR+50)
  8647. #define WSAENETUNREACH          (WSABASEERR+51)
  8648. #define WSAENETRESET            (WSABASEERR+52)
  8649. #define WSAECONNABORTED         (WSABASEERR+53)
  8650. #define WSAECONNRESET           (WSABASEERR+54)
  8651. #define WSAENOBUFS              (WSABASEERR+55)
  8652. #define WSAEISCONN              (WSABASEERR+56)
  8653. #define WSAENOTCONN             (WSABASEERR+57)
  8654. #define WSAESHUTDOWN            (WSABASEERR+58)
  8655. #define WSAETOOMANYREFS         (WSABASEERR+59)
  8656. #define WSAETIMEDOUT            (WSABASEERR+60)
  8657. #define WSAECONNREFUSED         (WSABASEERR+61)
  8658. #define WSAELOOP                (WSABASEERR+62)
  8659. #define WSAENAMETOOLONG         (WSABASEERR+63)
  8660. #define WSAEHOSTDOWN            (WSABASEERR+64)
  8661. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  8662. #define WSAENOTEMPTY            (WSABASEERR+66)
  8663. #define WSAEPROCLIM             (WSABASEERR+67)
  8664. #define WSAEUSERS               (WSABASEERR+68)
  8665. #define WSAEDQUOT               (WSABASEERR+69)
  8666. #define WSAESTALE               (WSABASEERR+70)
  8667. #define WSAEREMOTE              (WSABASEERR+71)
  8668.  
  8669. /*
  8670.  * Extended Winsock error constant definitions
  8671.  */
  8672. #define WSASYSNOTREADY          (WSABASEERR+91)
  8673. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  8674. #define WSANOTINITIALISED       (WSABASEERR+93)
  8675.  
  8676. /*
  8677.  * Error return codes from gethostbyname() and
  8678. gethostbyaddr()
  8679.  * (when using the resolver). Note that these errors are
  8680.  * retrieved via WSAGetLastError() and must therefore follow
  8681.  * the rules for avoiding clashes with error numbers from
  8682.  * specific implementations or language run-time systems.
  8683.  * For this reason the codes are based at WSABASEERR+1001.
  8684.  * Note also that [WSA]NO_ADDRESS is defined only for
  8685.  * compatibility purposes.
  8686.  */
  8687.  
  8688. #define h_errno         WSAGetLastError()
  8689.  
  8690. /* Authoritative Answer: Host not found */
  8691. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  8692. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  8693.  
  8694. /* Non-Authoritative: Host not found, or SERVERFAIL */
  8695. #define WSATRY_AGAIN            (WSABASEERR+1002)
  8696. #define TRY_AGAIN               WSATRY_AGAIN
  8697.  
  8698. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  8699. #define WSANO_RECOVERY          (WSABASEERR+1003)
  8700. #define NO_RECOVERY             WSANO_RECOVERY
  8701.  
  8702. /* Valid name, no data record of requested type */
  8703. #define WSANO_DATA              (WSABASEERR+1004)
  8704. #define NO_DATA                 WSANO_DATA
  8705.  
  8706. /* no address, look for MX record */
  8707. #define WSANO_ADDRESS           WSANO_DATA
  8708. #define NO_ADDRESS              WSANO_ADDRESS
  8709.  
  8710. /*
  8711.  * Winsock errors redefined as regular Berkeley error
  8712. constants
  8713.  */
  8714. #define EWOULDBLOCK             WSAEWOULDBLOCK
  8715. #define EINPROGRESS             WSAEINPROGRESS
  8716. #define EALREADY                WSAEALREADY
  8717. #define ENOTSOCK                WSAENOTSOCK
  8718. #define EDESTADDRREQ            WSAEDESTADDRREQ
  8719. #define EMSGSIZE                WSAEMSGSIZE
  8720. #define EPROTOTYPE              WSAEPROTOTYPE
  8721. #define ENOPROTOOPT             WSAENOPROTOOPT
  8722. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  8723. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  8724. #define EOPNOTSUPP              WSAEOPNOTSUPP
  8725. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  8726. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  8727. #define EADDRINUSE              WSAEADDRINUSE
  8728. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  8729. #define ENETDOWN                WSAENETDOWN
  8730. #define ENETUNREACH             WSAENETUNREACH
  8731. #define ENETRESET               WSAENETRESET
  8732. #define ECONNABORTED            WSAECONNABORTED
  8733. #define ECONNRESET              WSAECONNRESET
  8734. #define ENOBUFS                 WSAENOBUFS
  8735. #define EISCONN                 WSAEISCONN
  8736. #define ENOTCONN                WSAENOTCONN
  8737. #define ESHUTDOWN               WSAESHUTDOWN
  8738. #define ETOOMANYREFS            WSAETOOMANYREFS
  8739. #define ETIMEDOUT               WSAETIMEDOUT
  8740. #define ECONNREFUSED            WSAECONNREFUSED
  8741. #define ELOOP                   WSAELOOP
  8742. #define ENAMETOOLONG            WSAENAMETOOLONG
  8743. #define EHOSTDOWN               WSAEHOSTDOWN
  8744. #define EHOSTUNREACH            WSAEHOSTUNREACH
  8745. #define ENOTEMPTY               WSAENOTEMPTY
  8746. #define EPROCLIM                WSAEPROCLIM
  8747. #define EUSERS                  WSAEUSERS
  8748. #define EDQUOT                  WSAEDQUOT
  8749. #define ESTALE                  WSAESTALE
  8750. #define EREMOTE                 WSAEREMOTE
  8751.  
  8752. #endif   /* _WS2API_ */
  8753.  
  8754. /*
  8755.  *  Winsock SPI socket function prototypes
  8756.  */
  8757.  
  8758. #ifdef __cplusplus
  8759. extern "C" {
  8760. #endif
  8761.  
  8762. typedef BOOL ( WSACALLBACK * LPBLOCKINGPROC )( VOID );
  8763.  
  8764. typedef VOID ( WSACALLBACK * LPCLEANUPPROC )( int ErrorCode,
  8765.                                               DWORD
  8766. dwCallbackData );
  8767.  
  8768. typedef int ( WSACALLBACK * LPCONDITIONPROC )( LPWSABUF
  8769. lpCallerId,
  8770.                                                LPWSABUF
  8771. lpCallerData,
  8772.                                                LPWSABUF
  8773. lpCalleeId,
  8774.                                                LPWSABUF
  8775. lpCalleeData,
  8776.                                                GROUP FAR *
  8777. g,
  8778.                                                DWORD
  8779. dwCallbackData );
  8780.  
  8781. typedef VOID ( WSACALLBACK LPSELECTPROC )( SOCKET s,
  8782.                                            long lEvent,
  8783.                                            int ErrorCode,
  8784.                                            DWORD
  8785. dwCallbackData );
  8786.  
  8787. typedef VOID ( FAR * LPWSAUSERAPC )( DWORD dwContext );
  8788.  
  8789. SOCKET PASCAL FAR PSaccept (SOCKET s,
  8790.                             struct sockaddr FAR *addr,
  8791.                             int FAR *addrlen,
  8792.                             int FAR * lpErrno);
  8793.  
  8794. int WSPAPI WSPBindWSPbind( SOCKET s,
  8795.                     const struct sockaddr FAR *name,
  8796.                     int namelen,
  8797.                     int FAR * lpErrno );
  8798.  
  8799. int WSPAPI WSPCloseSocketWSPclosesocket( SOCKET s,
  8800.                            int FAR * lpErrno );
  8801.  
  8802. int PASCAL FAR PSconnect (SOCKET s,
  8803.                           const struct sockaddr FAR *name,
  8804.                           int namelen,
  8805.                           int FAR * lpErrno);
  8806.  
  8807. int WSPAPI WSPGetPeerNameWSPgetpeername( SOCKET s,
  8808.                            struct sockaddr FAR *name,
  8809.                            int FAR * namelen,
  8810.                            int FAR * lpErrno );
  8811.  
  8812. int WSPAPI WSPGetSockNameWSPgetsockname( SOCKET s,
  8813.                            struct sockaddr FAR *name,
  8814.                            int FAR * namelen,
  8815.                            int FAR * lpErrno );
  8816.  
  8817. int WSPAPI WSPGetSockOptWSPgetsockopt( SOCKET s,
  8818.                           int level,
  8819.                           int optname,
  8820.                           char FAR * optval,
  8821.                           int FAR *optlen,
  8822.                           int FAR * lpErrno );
  8823.  
  8824. int WSPAPI WSPIoctlSocketWSPioctlsocket( SOCKET s,
  8825.                            long cmd,
  8826.                            u_long FAR *argp,
  8827.                            int FAR * lpErrno );
  8828.  
  8829. int WSPAPI WSPListenWSPlisten( SOCKET s,
  8830.                       int backlog,
  8831.                       int FAR * lpErrno );
  8832.  
  8833. int WSPAPI WSPSelectWSPselect( int nfds,
  8834.                       fd_set FAR *readfds,
  8835.                       fd_set FAR *writefds,
  8836.                       fd_set FAR *exceptfds,
  8837.                       const struct timeval FAR *timeout,
  8838.                       int FAR * lpErrno );
  8839.  
  8840. int WSPAPI WSPSetSockOptWSPsetsockopt( SOCKET s,
  8841.                           int level,
  8842.                           int optname,
  8843.                           const char FAR * optval,
  8844.                           int optlen,
  8845.                           int FAR * lpErrno );
  8846.  
  8847. int WSPAPI WSPShutdownWSPshutdown( SOCKET s,
  8848.                         int how,
  8849.                         int FAR * lpErrno );
  8850.  
  8851. /* Microsoft Windows Extension function prototypes */
  8852.  
  8853. SOCKET WSPAPI WSPAccept( SOCKET s,
  8854.                          struct sockaddr FAR *addr,
  8855.                          int FAR *addrlen,
  8856.                          LPCONDITIONPROC lpfnCondition,
  8857.                          DWORD dwCallbackData,
  8858.                          int FAR * lpErrno );
  8859.  
  8860. int WSPAPI WSPAsyncSelect32( SOCKET s,
  8861.                              HWND hWnd,
  8862.                              unsigned int wMsg,
  8863.                              long lEvnet,
  8864.                              int FAR * lpErrno );
  8865.  
  8866. int WSPAPI WSPCallbackSelect16( SOCKET s,
  8867.                                 LPSELECTPROC lpfnCallback,
  8868.                                 DWORD dwCallbackData,
  8869.                                 long lEvent,
  8870.                                 int FAR * lpErrno );
  8871.  
  8872. int WSPAPI WSPCancelBlockingCall32( int FAR * lpErrno );
  8873.  
  8874. int WSPAPI WSPCleanup( LPCLEANUPPROC lpfnCallback,
  8875.                        DWORD dwCallbackData,
  8876.                        int FAR * lpErrno );
  8877.  
  8878. int WSPAPI WSPConnect( SOCKET s,
  8879.                        const struct sockaddr FAR *name,
  8880.                        int namelen,
  8881.                        LPWSABUF lpCallerData,
  8882.                        LPWSABUF lpCalleeData,
  8883.                        GROUP g,
  8884.                        LPQOS lpSFlowspec,
  8885.                        LPQOS lpGFlowspec,
  8886.                        int FAR * lpErrno );
  8887.  
  8888. int WSPAPI WSPEnumNetworkEvents( SOCKET s,
  8889.                                  WSAEVNET hEventObject,
  8890.                                  LPWSANETWORKEVENT
  8891. lpNetworkEvents,
  8892.                                  LPINT lpiCount,
  8893.                                  int FAR * lpErrno  );
  8894.  
  8895. int WSPAPI WSPEventSelect( SOCKET s,
  8896.                            WSAEVENT hEventObject,
  8897.                            long lNetworkEvents,
  8898.                            int FAR * lpErrno  );
  8899.  
  8900. BOOL WSPAPI WSPIsBlocking32( VOID );
  8901.  
  8902. int WSPAPI WSPRecvWSPrecv( SOCKET s,
  8903.                     LPVOID lpBuffer,
  8904.                     DWORD nNumberOfBytesToRecv,
  8905.                     LPDWORD lpNumberOfBytesRecvd,
  8906.                     LPINT lpFlags,
  8907.                     LPWSAOVERLAPPED lpOverlapped,
  8908.                     LPWSAOVERLAPPED_COMPLETION_ROUTINE
  8909. lpCompletionRoutine,
  8910.                     int FAR * lpErrno );
  8911.  
  8912. int WSPAPI WSPRecvFromWSPrecvfrom( SOCKET s,
  8913.                         LPVOID lpBuffer,
  8914.                         DWORD nNumberOfBytesToRecv,
  8915.                         LPDWORD lpNumberOfBytesRecvd,
  8916.                         LPINT lpFlags,
  8917.                         LPVOID lpFrom,
  8918.                         LPINT lpFromlen,
  8919.                         LPWSAOVERLAPPED lpOverlapped,
  8920.                         LPWSAOVERLAPPED_COMPLETION_ROUTINE
  8921. lpCompletionRoutine,
  8922.                         int FAR * lpErrno );
  8923.  
  8924. int WSPAPI WSPSendWSPsend( SOCKET s,
  8925.                     LPVOID lpBuffer,
  8926.                     DWORD nNumberOfBytesToSend,
  8927.                     LPDWORD lpNumberOfBytesSent,
  8928.                     int nFlags,
  8929.                     LPWSAOVERLAPPED lpOverlapped,
  8930.                     LPWSAOVERLAPPED_COMPLETION_ROUTINE
  8931. lpCompletionRoutine,
  8932.                     int FAR * lpErrno );
  8933.  
  8934. int WSPAPI WSPSendToWSPsendto( SOCKET s,
  8935.                       LPVOID lpBuffer,
  8936.                       DWORD nNumberOfBytesToSend,
  8937.                       LPDWORD lpNumberOfBytesSent,
  8938.                       int nFlags,
  8939.                       LPVOID lpTo,
  8940.                       int nTolen,
  8941.                       LPWSAOVERLAPPED lpOverlapped,
  8942.                       LPWSAOVERLAPPED_COMPLETION_ROUTINE
  8943. lpCompletionRoutine,
  8944.                       int FAR * lpErrno );
  8945.  
  8946. LPBLOCKINGPROC WSPAPI WSPSetBlockingHook32( LPBLOCKINGPROC
  8947. lpBlockFunc,
  8948.                                             int FAR *
  8949. lpErrno );
  8950.  
  8951. SOCKET WSPAPI WSPSocket( int af,
  8952.                          int type,
  8953.                          int protocol,
  8954.                          DWORD dwProviderId,
  8955.                          int nFlags,
  8956.                          int FAR * lpErrno );
  8957.  
  8958. int WSPAPI WSPStartup( WORD wVersionRequired,
  8959.                        LPWSADATA lpWSAData );
  8960.  
  8961. int WSPAPI WSPUnhookBlockingHook32( int FAR * lpErrno );
  8962.  
  8963. /* Upcalls from service providers to the Winsock DLL */
  8964.  
  8965. SOCKETWSPAPI WPUXxxCreateSocketHandle( DWORD dwProviderId,
  8966.                                     LPVOID lpContext,
  8967.                                     int FAR * lpErrno );
  8968.  
  8969. int WSPAPI WPUXxxCloseSocketHandle( SOCKET s,
  8970.                                  int FAR * lpErrno );
  8971.  
  8972. int WSPAPI WPUXxxQuerySocketHandleContext( SOCKET s,
  8973.                                         LPVOID FAR *
  8974. lpContext,
  8975.                                         int FAR * lpErrno );
  8976.  
  8977. int WSPAPI WPUXxxSetSocketHandleContext( SOCKET s,
  8978.                                       LPVOID lpContext,
  8979.                                       int FAR * lpErrno );
  8980.  
  8981. int WSPAPI WPUXxxQueueUserAPC32UserAPC( DWORD dwThreadId,
  8982.                               LPWSAUSERAPC lpfnUserApc,
  8983.                               DWORD dwContext,
  8984.                               int FAR * lpErrno );
  8985.  
  8986. DWORD WSPAPI WPUXxxGetCurrentThreadId32( VOID );
  8987.  
  8988. #ifdef __cplusplus
  8989. }
  8990. #endif
  8991.  
  8992. #ifndef _WS2API_
  8993.  
  8994. /* Microsoft Windows Extended data types */
  8995. typedef struct sockaddr SOCKADDR;
  8996. typedef struct sockaddr *PSOCKADDR;
  8997. typedef struct sockaddr FAR *LPSOCKADDR;
  8998.  
  8999. typedef struct sockaddr_in SOCKADDR_IN;
  9000. typedef struct sockaddr_in *PSOCKADDR_IN;
  9001. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  9002.  
  9003. typedef struct linger LINGER;
  9004. typedef struct linger *PLINGER;
  9005. typedef struct linger FAR *LPLINGER;
  9006.  
  9007. typedef struct in_addr IN_ADDR;
  9008. typedef struct in_addr *PIN_ADDR;
  9009. typedef struct in_addr FAR *LPIN_ADDR;
  9010.  
  9011. typedef struct fd_set FD_SET;
  9012. typedef struct fd_set *PFD_SET;
  9013. typedef struct fd_set FAR *LPFD_SET;
  9014.  
  9015. typedef struct hostent HOSTENT;
  9016. typedef struct hostent *PHOSTENT;
  9017. typedef struct hostent FAR *LPHOSTENT;
  9018.  
  9019. typedef struct servent SERVENT;
  9020. typedef struct servent *PSERVENT;
  9021. typedef struct servent FAR *LPSERVENT;
  9022.  
  9023. typedef struct protoent PROTOENT;
  9024. typedef struct protoent *PPROTOENT;
  9025. typedef struct protoent FAR *LPPROTOENT;
  9026.  
  9027. typedef struct timeval TIMEVAL;
  9028. typedef struct timeval *PTIMEVAL;
  9029. typedef struct timeval FAR *LPTIMEVAL;
  9030.  
  9031. /*
  9032.  * Windows message parameter composition and decomposition
  9033.  * macros.
  9034.  *
  9035.  * WSAMAKEASYNCREPLY is intended for use by Winsock
  9036.  * when constructing the response to a WSAAsyncGetXByY()
  9037. routine.
  9038.  */
  9039. #define WSAMAKEASYNCREPLY(buflen,error)
  9040. MAKELONG(buflen,error)
  9041. /*
  9042.  * WSAMAKESELECTREPLY is intended for use by Winsock
  9043.  * when constructing the response to WSAAsyncSelect().
  9044.  */
  9045. #define WSAMAKESELECTREPLY(event,error)
  9046. MAKELONG(event,error)
  9047. /*
  9048.  * WSAGETASYNCBUFLEN is intended for use by the Winsock
  9049. application
  9050.  * to extract the buffer length from the lParam in the
  9051. response
  9052.  * to a WSAGetXByY().
  9053.  */
  9054. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  9055. /*
  9056.  * WSAGETASYNCERROR is intended for use by the Winsock
  9057. application
  9058.  * to extract the error code from the lParam in the response
  9059.  * to a WSAGetXByY().
  9060.  */
  9061. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  9062. /*
  9063.  * WSAGETSELECTEVENT is intended for use by the Winsock
  9064. application
  9065.  * to extract the event code from the lParam in the response
  9066.  * to a WSAAsyncSelect().
  9067.  */
  9068. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  9069. /*
  9070.  * WSAGETSELECTERROR is intended for use by the Winsock
  9071. application
  9072.  * to extract the error code from the lParam in the response
  9073.  * to a WSAAsyncSelect().
  9074.  */
  9075. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  9076.  
  9077. #endif  /* _WS2API_ */
  9078.  
  9079. #endif  /* _WS2SPI_ */
  9080.  
  9081.  
  9082. Appendix B. Notes for Winsock Service Providers
  9083. B.1 Introduction
  9084.  
  9085. A Winsock service provider must implement ALL of the
  9086. applicable functionality described in the Winsock SPI
  9087. documentation. Validation of compliance is discussed in
  9088. section Error! Reference source not found.Error! Reference
  9089. source not found.Error! Reference source not found..
  9090.  
  9091. PII Version 1.1 implementations must support both TCP and
  9092. UDP type sockets.  An implementation may support raw sockets
  9093. (of type SOCK_RAW), but their use is deprecated.
  9094.  
  9095. Certain Winsock SPIs documented above have special notes for
  9096. Winsock service provider implementors. A Winsock service
  9097. provider should pay special attention to conforming to the
  9098. Winsock SPI as documented. The Special Notes are provided
  9099. for assistance and clarification.
  9100.  
  9101. B.2 Winsock SPI Run Time Components
  9102.  
  9103. The run time component provided by each Winsock supplier is:
  9104.  
  9105. Component           Description
  9106. Installation Program     The Winsock service provider
  9107.                     installation program
  9108. Service Provider DLL     The Winsock service provider
  9109.                     implementation DLL
  9110.  
  9111. B.3 Error Codes
  9112.  
  9113. In order to avoid conflict between various compiler
  9114. environments Winsock service providers MUST return the error
  9115. codes listed in the SPI specification, using the manifest
  9116. constants beginning with "WSA". The Berkeley-compatible
  9117. error code definitions are provided solely for compatibility
  9118. purposes for applications which are being ported from other
  9119. platforms.
  9120. Appendix C. Outstanding Issues
  9121.  
  9122.   1.   Does the 32-bit Windows Sockets 2 implementation live
  9123.      in WSOCK32.DLL or WSOCK232.DLL?
  9124.   
  9125.   What is the exact mechanism used for routing socket
  9126.      handle-based requests to the proper provider? This
  9127.      mechanism needs to be cognizant of TDI providers that
  9128.      use "real" file system handles. {Is this an
  9129.      architectural issue or an implementation issue. I would
  9130.      suggest we avoid raising implimentation issues in our
  9131.      public forum at this point in time.}
  9132.   Does Windows 95 support 16- and 32-bit providers? If so,
  9133.      the registry layout may need to be changed slighly to
  9134.      specify both 16- and 32-bit provider DLLs. The registry
  9135.      could be split into 16- and 32-bit subtrees, or
  9136.      separate registry values could be used for the 16- and
  9137.      32-bit DLLs. {I thought we had decided that there would
  9138.      only be 32 bit providers in Windows 95}
  9139.   The (16- and 32-bit) Windows Sockets DLLs could provide
  9140.      "up call" entrypoints for use by the provider DLLs to
  9141.      simplify configuration management. The Windows Sockets
  9142.      DLLs could also provide entrypoints to simplify
  9143.      provider installation. {Are these different upcalls
  9144.      than are already included in this document? If so, I'm
  9145.      not sure what you mean by "simplify configuration
  9146.      mgmt". I believe we made a decision that the Winsock
  9147.      DLLs would in fact provide entry points to simplify
  9148.      installation. Even if we don't have these ready at this
  9149.      time, we should put a place holder for them in the main
  9150.      body of the document and not show them as an open
  9151.      issue. }
  9152.   2.   Do the 16- and 32-bit providers use the same header
  9153.      file (ws2spi.h)?
  9154.   
  9155.   Need proper prefix for upcalls ("Xxx" is obviously just a
  9156.      place-holder). {How about WSU for Winsock upcall ? It
  9157.      would be nice not to have a relatively minor point like
  9158.      this left in the Opens section.}
  9159.   3.   Should SPI functions that take socket descriptors also
  9160.      take a context value? For providers that use "real" system
  9161.      handles, this could always be NULL.
  9162.   Should we support the SPI version as a separate concept
  9163.      from the API version? {I think we are already set up to
  9164.      be able to do this since we have separate version
  9165.      negotiations between App and DLL and between DLL and
  9166.      SP.}
  9167.   Does the 32-bit WSPCleanup() really use the callback
  9168.      function? {Again, is this architecture or
  9169.      implementation? If implementation, lets move this to a
  9170.      private list of implementation issues.}
  9171.   4.   How does a DLL-based protocol support graceful socket
  9172.      close if an app immediately exits after calling
  9173.      closesocket()? The provider & protocol DLLs will be detached
  9174.      from the process (whose address space will go away
  9175.      entirely), yet socket state needs to "linger" for the
  9176.      graceful close.
  9177.   5.   Does the Winsock DLL close all sockets before calling
  9178.      WSPCleanup(), or is WSPCleanup() responsible for closing all
  9179.      open sockets?
  9180. _______________________________
  9181. 1Note that there is a timing window between the accept()
  9182. call and the call to WSAAsyncSelect() to change the events
  9183. or wMsg.  An application which desires a different wMsg for
  9184. the listening and accept()'ed sockets should ask for only
  9185. FD_ACCEPT events on the listening socket, then set
  9186. appropriate events after the accept().  Since FD_ACCEPT is
  9187. never sent for a connected socket and FD_READ, FD_WRITE,
  9188. FD_OOB, and FD_CLOSE are never sent for listening sockets,
  9189. this will not impose difficulties.
  9190. 2 Because the callback is accessed at interrupt time, it
  9191. must reside in a DLL, and its code segment must be specified
  9192. as FIXED in the module-definition file for the DLL. Any data
  9193. that the callback accesses must be in a FIXED data segment
  9194. as well. The callback may not make any system calls except
  9195. for PostMessage, timeGetSystemTime, timeGetTime,
  9196. timeSetEvent, timeKillEvent, midiOutShortMsg,
  9197. midiOutLongMsg, and OutputDebugStr.
  9198. 3 Note that there is a potential race condition here:
  9199. WINSOCK 2..DLL may get FD_READ,  FD_WRITE or FD_ACCEPT
  9200. callback in interrupt time before it returns from
  9201. WSPAcceptEx().  Similar situations may happen to
  9202. PSConnectEx(), andany of the reenabling functions if they
  9203. are not invoked from within callback context.
  9204. 4 However, due to the independence feature of sockets,
  9205. WINSOCK2.DLL may get a callback for one socket before the
  9206. callback for another socket has returned.  WINSOCK2.DLL may
  9207. need to coordinate access to any common memory area shared
  9208. amongst these callback driven sockets.
  9209. 5 Note that there is a potential race condition here:
  9210. WINSOCK2.DLL may get a callback in interrupt time even
  9211. before returning from WSPCallbackSelect(), in which case
  9212. WINSOCK2.DLL should proceed with the callback and assume
  9213. that WSPCallbackSelect() will return 0.
  9214. 6Note that there is a timing window between the accept()
  9215. call and the call to WSAEventSelect() to change the network
  9216. events or hEventObject.  An application which desires a
  9217. different hEventObject for the listening and accept()'ed
  9218. sockets should ask for only FD_ACCEPT network event on the
  9219. listening socket, then set appropriate network events after
  9220. the accept().  Since FD_ACCEPT never happens to a connected
  9221. socket and FD_READ, FD_WRITE, FD_OOB, and FD_CLOSE never
  9222. happen to listening sockets, this will not impose
  9223. difficulties.
  9224.